gunzip: inflate_codes(): add fix from upstream gzip to prevent false CRC error
authorJoakim Tjernlund <Joakim.Tjernlund@transmode.se>
Mon, 8 Feb 2010 17:55:15 +0000 (18:55 +0100)
committerDenys Vlasenko <vda.linux@googlemail.com>
Thu, 11 Feb 2010 22:56:48 +0000 (23:56 +0100)
Signed-off-by: Joakim Tjernlund <Joakim.Tjernlund@transmode.se>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
archival/libunarchive/decompress_unzip.c

index feaa047bd6b2e160228d023f67aca1cec06fdde2..33e877ec81a4e2c252eea415e5f7c748a3b82ade 100644 (file)
@@ -575,13 +575,16 @@ static NOINLINE int inflate_codes(STATE_PARAM_ONLY)
                        do {
                                /* Was: nn -= (e = (e = GUNZIP_WSIZE - ((dd &= GUNZIP_WSIZE - 1) > w ? dd : w)) > nn ? nn : e); */
                                /* Who wrote THAT?? rewritten as: */
+                               unsigned delta;
+
                                dd &= GUNZIP_WSIZE - 1;
                                e = GUNZIP_WSIZE - (dd > w ? dd : w);
+                               delta = w > dd ? w - dd : dd - w;
                                if (e > nn) e = nn;
                                nn -= e;
 
                                /* copy to new buffer to prevent possible overwrite */
-                               if (w - dd >= e) {      /* (this test assumes unsigned comparison) */
+                               if (delta >= e) {
                                        memcpy(gunzip_window + w, gunzip_window + dd, e);
                                        w += e;
                                        dd += e;