Skip to content

Commit

Permalink
core: check buffer size before checking type
Browse files Browse the repository at this point in the history
  • Loading branch information
myfreeer committed Apr 9, 2018
1 parent 907b2a9 commit 29c4c48
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions node-chrome-pak.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,11 +156,13 @@ function unpack_proc(pak_file_path, extract_dst_dir) {
var res_file_name = res_info[i].id.toString();

var res_buf = pak_buf.slice(res_info[i].offset, res_info[i].offset + size);
if (res_buf.readUInt32BE(0x00) == 0x89504E47) { // ‰PNG
res_file_name += ".png";
}
if (res_buf.readUInt32BE(0x00) == 0x3C21646F || res_buf.readUInt32BE(0x00) == 0x3C68746D) { // ‰HTML
res_file_name += ".htm";
if (size >= 4 ) {
if (res_buf.readUInt32BE(0x00) == 0x89504E47) { // ‰PNG
res_file_name += ".png";
}
if (res_buf.readUInt32BE(0x00) == 0x3C21646F || res_buf.readUInt32BE(0x00) == 0x3C68746D) { // ‰HTML
res_file_name += ".htm";
}
}

if (!fs.existsSync(dst_dir)) { fs.mkdirSync(dst_dir); }
Expand All @@ -169,4 +171,4 @@ function unpack_proc(pak_file_path, extract_dst_dir) {
}

console.log("unpack process complete!");
}
}

0 comments on commit 29c4c48

Please sign in to comment.