From 21c21df425350f92e4bc026cb4c9b1d2055b71d7 Mon Sep 17 00:00:00 2001 From: Vitaly Puzrin Date: Thu, 13 Mar 2014 23:43:30 +0400 Subject: [PATCH] Polished ungzip crc32 check --- lib/zlib/inflate.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/zlib/inflate.js b/lib/zlib/inflate.js index 3d4a740..2c29675 100644 --- a/lib/zlib/inflate.js +++ b/lib/zlib/inflate.js @@ -1356,8 +1356,8 @@ function inflate(strm, flush) { while (bits < 32) { if (have === 0) { break inf_leave; } have--; - hold += input[next++] << bits; - hold >>>= 0; + // Use '|' insdead of '+' to make sure that result is signed + hold |= input[next++] << bits; bits += 8; } //===// @@ -1371,7 +1371,8 @@ function inflate(strm, flush) { } _out = left; - if ((state.flags ? hold : ZSWAP32(hold) >>> 0) !== state.check >>> 0) { + // NB: crc32 stored as signed 32-bit int, ZSWAP32 returns signed too + if ((state.flags ? hold : ZSWAP32(hold)) !== state.check) { strm.msg = 'incorrect data check'; state.mode = BAD; break;