From 3d6aee3e8d8c132327d6eef40c2760e40707c9e7 Mon Sep 17 00:00:00 2001 From: Kevin Tjiam Date: Fri, 25 May 2018 11:15:24 +0800 Subject: [PATCH 1/3] handle errors in callback from getDataAsync --- adm-zip.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/adm-zip.js b/adm-zip.js index a55d794..612ebf6 100644 --- a/adm-zip.js +++ b/adm-zip.js @@ -113,7 +113,12 @@ module.exports = function (/*String*/input) { readAsTextAsync: function (/*Object*/entry, /*Function*/callback, /*String - Optional*/encoding) { var item = getEntry(entry); if (item) { - item.getDataAsync(function (data) { + item.getDataAsync(function (data, err) { + if (err) { + callback(data, err); + return; + } + if (data && data.length) { callback(data.toString(encoding || "utf8")); } else { @@ -470,8 +475,12 @@ module.exports = function (/*String*/input) { callback(undefined); return; } - entry.getDataAsync(function (content) { + entry.getDataAsync(function (content, err) { if (i <= 0) return; + if (err) { + callback(new Error(err)); + return; + } if (!content) { i = 0; callback(new Error(Utils.Errors.CANT_EXTRACT_FILE)); From beff650f6e37e7ed4ed7fb088129569c0fbabd3c Mon Sep 17 00:00:00 2001 From: Kevin Tjiam Date: Fri, 25 May 2018 12:27:14 +0800 Subject: [PATCH 2/3] compare calculated CRC with loaded CRC --- zipEntry.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zipEntry.js b/zipEntry.js index 1e9f797..4ce74a5 100644 --- a/zipEntry.js +++ b/zipEntry.js @@ -23,7 +23,7 @@ module.exports = function (/*Buffer*/input) { function crc32OK(data) { // if bit 3 (0x08) of the general-purpose flags field is set, then the CRC-32 and file sizes are not known when the header is written if ((_entryHeader.flags & 0x8) !== 0x8) { - if (Utils.crc32(data) !== _entryHeader.crc) { + if (Utils.crc32(data) !== _entryHeader.dataHeader.crc) { return false; } } else { From f5310b54e04b766d26580fda6d0351df5ed26f9c Mon Sep 17 00:00:00 2001 From: Kevin Tjiam Date: Fri, 25 May 2018 12:32:48 +0800 Subject: [PATCH 3/3] add tests for CRC fixes --- test/crc/bad_crc.zip | Bin 0 -> 1509 bytes test/crc/good_crc.zip | Bin 0 -> 1509 bytes test/crc/index.js | 44 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 44 insertions(+) create mode 100644 test/crc/bad_crc.zip create mode 100644 test/crc/good_crc.zip create mode 100644 test/crc/index.js diff --git a/test/crc/bad_crc.zip b/test/crc/bad_crc.zip new file mode 100644 index 0000000000000000000000000000000000000000..26b4c0999b8846fbb077c489264a5df6b2437fd2 GIT binary patch literal 1509 zcmVD$Kr$MV06iO??xrrk~mDK?Uvy=CP)BIG$RL<7y-a1OQEaq)7x9DrxExfVa z#Q%)~1zR{HJnw53BghONZq@I#*g}i>pkA&B@|x_8S8E)c=ja&k@H&dOUF}?Ih9ij{ zw=aC5AaPRQ%{*Ago->{dD}m%8FuYlhlf}H3sMZ+BozX0ba}kRM9}t-wKTy50B=sdx zVS!?VYqH&$g5JvZ%0-fEcy55iQ?7OewBHhN=5;~>oM7BrQ~|Mv7#8#O@SK5@6IkSk z`iH|Ba@z>;f3(#J1m?!YQuC@0oT=X1&Be4+THd@l8IDNZaj7ei4}5t%*ah6Ll#9(u zB>8FS?>%El2v{Fj=oR0hyx}1N@l{e*1Wx`NZKSNUfh@SAemeoS=;bk)P=gZ~%*ETV za_M~1S|THmQ@;bkR>y(y*|*YnymvK8{4EQq-N%ITG6FMIih=Gxs0BTe9%GPVXio^N zFEGb|kx7BtBtKL^th7s7ipBiPH%iI2RQ2*+{f&c710l^gfO&+6M2X7)=}rae;dKl&_oFk~JzVh=%_^2FD)VQD0J?@Q9F;@DkJjPmf=7Y| zw55dZ&e#N=2E=jL+6*ds`_Bys+=pB^dY?{PyjYtqscReBH&(5W`SSI=4e z-aTW?fVJ@t6o|P}`c4u?ri}q0z=&Wm?_~Jku$%^hO_(+lr%vsYmjA7-4!mR(tw)Sq zH}(_~*rCGVBE?EE5Kv%NhVgsR*q%k%BfB}p7r1uMuNGH|QjzdYhB)GU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