diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2015-10-30 23:41:53 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2015-10-30 23:41:53 +0100 |
commit | 6bd3fff51aa74e2ee2d87887b12182a3b09792ef (patch) | |
tree | 84b3db20aa35689538306483c0c2be9ec4670253 | |
parent | 95650a86d176ee83a264fd9e7047c414b71ee7cb (diff) | |
download | busybox-w32-6bd3fff51aa74e2ee2d87887b12182a3b09792ef.tar.gz busybox-w32-6bd3fff51aa74e2ee2d87887b12182a3b09792ef.tar.bz2 busybox-w32-6bd3fff51aa74e2ee2d87887b12182a3b09792ef.zip |
[g]unzip: fix recent breakage.
Also, do emit error message we so painstakingly pass from gzip internals
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | archival/libarchive/decompress_gunzip.c | 33 | ||||
-rwxr-xr-x | testsuite/unzip.tests | 1 |
2 files changed, 22 insertions, 12 deletions
diff --git a/archival/libarchive/decompress_gunzip.c b/archival/libarchive/decompress_gunzip.c index 30bf45154..20e4d9ac5 100644 --- a/archival/libarchive/decompress_gunzip.c +++ b/archival/libarchive/decompress_gunzip.c | |||
@@ -309,8 +309,7 @@ static int huft_build(const unsigned *b, const unsigned n, | |||
309 | huft_t *q; /* points to current table */ | 309 | huft_t *q; /* points to current table */ |
310 | huft_t r; /* table entry for structure assignment */ | 310 | huft_t r; /* table entry for structure assignment */ |
311 | huft_t *u[BMAX]; /* table stack */ | 311 | huft_t *u[BMAX]; /* table stack */ |
312 | unsigned v[N_MAX]; /* values in order of bit length */ | 312 | unsigned v[N_MAX + 1]; /* values in order of bit length. last v[] is never used */ |
313 | unsigned v_end; | ||
314 | int ws[BMAX + 1]; /* bits decoded stack */ | 313 | int ws[BMAX + 1]; /* bits decoded stack */ |
315 | int w; /* bits decoded */ | 314 | int w; /* bits decoded */ |
316 | unsigned x[BMAX + 1]; /* bit offsets, then code stack */ | 315 | unsigned x[BMAX + 1]; /* bit offsets, then code stack */ |
@@ -365,15 +364,17 @@ static int huft_build(const unsigned *b, const unsigned n, | |||
365 | *xp++ = j; | 364 | *xp++ = j; |
366 | } | 365 | } |
367 | 366 | ||
368 | /* Make a table of values in order of bit lengths */ | 367 | /* Make a table of values in order of bit lengths. |
368 | * To detect bad input, unused v[i]'s are set to invalid value UINT_MAX. | ||
369 | * In particular, last v[i] is never filled and must not be accessed. | ||
370 | */ | ||
371 | memset(v, 0xff, sizeof(v)); | ||
369 | p = b; | 372 | p = b; |
370 | i = 0; | 373 | i = 0; |
371 | v_end = 0; | ||
372 | do { | 374 | do { |
373 | j = *p++; | 375 | j = *p++; |
374 | if (j != 0) { | 376 | if (j != 0) { |
375 | v[x[j]++] = i; | 377 | v[x[j]++] = i; |
376 | v_end = x[j]; | ||
377 | } | 378 | } |
378 | } while (++i < n); | 379 | } while (++i < n); |
379 | 380 | ||
@@ -435,7 +436,9 @@ static int huft_build(const unsigned *b, const unsigned n, | |||
435 | 436 | ||
436 | /* set up table entry in r */ | 437 | /* set up table entry in r */ |
437 | r.b = (unsigned char) (k - w); | 438 | r.b = (unsigned char) (k - w); |
438 | if (p >= v + v_end) { // Was "if (p >= v + n)" but v[] can be shorter! | 439 | if (/*p >= v + n || -- redundant, caught by the second check: */ |
440 | *p == UINT_MAX /* do we access uninited v[i]? (see memset(v))*/ | ||
441 | ) { | ||
439 | r.e = 99; /* out of values--invalid code */ | 442 | r.e = 99; /* out of values--invalid code */ |
440 | } else if (*p < s) { | 443 | } else if (*p < s) { |
441 | r.e = (unsigned char) (*p < 256 ? 16 : 15); /* 256 is EOB code */ | 444 | r.e = (unsigned char) (*p < 256 ? 16 : 15); /* 256 is EOB code */ |
@@ -520,8 +523,9 @@ static NOINLINE int inflate_codes(STATE_PARAM_ONLY) | |||
520 | e = t->e; | 523 | e = t->e; |
521 | if (e > 16) | 524 | if (e > 16) |
522 | do { | 525 | do { |
523 | if (e == 99) | 526 | if (e == 99) { |
524 | abort_unzip(PASS_STATE_ONLY);; | 527 | abort_unzip(PASS_STATE_ONLY); |
528 | } | ||
525 | bb >>= t->b; | 529 | bb >>= t->b; |
526 | k -= t->b; | 530 | k -= t->b; |
527 | e -= 16; | 531 | e -= 16; |
@@ -557,8 +561,9 @@ static NOINLINE int inflate_codes(STATE_PARAM_ONLY) | |||
557 | e = t->e; | 561 | e = t->e; |
558 | if (e > 16) | 562 | if (e > 16) |
559 | do { | 563 | do { |
560 | if (e == 99) | 564 | if (e == 99) { |
561 | abort_unzip(PASS_STATE_ONLY); | 565 | abort_unzip(PASS_STATE_ONLY); |
566 | } | ||
562 | bb >>= t->b; | 567 | bb >>= t->b; |
563 | k -= t->b; | 568 | k -= t->b; |
564 | e -= 16; | 569 | e -= 16; |
@@ -824,8 +829,9 @@ static int inflate_block(STATE_PARAM smallint *e) | |||
824 | 829 | ||
825 | b_dynamic >>= 4; | 830 | b_dynamic >>= 4; |
826 | k_dynamic -= 4; | 831 | k_dynamic -= 4; |
827 | if (nl > 286 || nd > 30) | 832 | if (nl > 286 || nd > 30) { |
828 | abort_unzip(PASS_STATE_ONLY); /* bad lengths */ | 833 | abort_unzip(PASS_STATE_ONLY); /* bad lengths */ |
834 | } | ||
829 | 835 | ||
830 | /* read in bit-length-code lengths */ | 836 | /* read in bit-length-code lengths */ |
831 | for (j = 0; j < nb; j++) { | 837 | for (j = 0; j < nb; j++) { |
@@ -906,12 +912,14 @@ static int inflate_block(STATE_PARAM smallint *e) | |||
906 | bl = lbits; | 912 | bl = lbits; |
907 | 913 | ||
908 | i = huft_build(ll, nl, 257, cplens, cplext, &inflate_codes_tl, &bl); | 914 | i = huft_build(ll, nl, 257, cplens, cplext, &inflate_codes_tl, &bl); |
909 | if (i != 0) | 915 | if (i != 0) { |
910 | abort_unzip(PASS_STATE_ONLY); | 916 | abort_unzip(PASS_STATE_ONLY); |
917 | } | ||
911 | bd = dbits; | 918 | bd = dbits; |
912 | i = huft_build(ll + nl, nd, 0, cpdist, cpdext, &inflate_codes_td, &bd); | 919 | i = huft_build(ll + nl, nd, 0, cpdist, cpdext, &inflate_codes_td, &bd); |
913 | if (i != 0) | 920 | if (i != 0) { |
914 | abort_unzip(PASS_STATE_ONLY); | 921 | abort_unzip(PASS_STATE_ONLY); |
922 | } | ||
915 | 923 | ||
916 | /* set up data for inflate_codes() */ | 924 | /* set up data for inflate_codes() */ |
917 | inflate_codes_setup(PASS_STATE bl, bd); | 925 | inflate_codes_setup(PASS_STATE bl, bd); |
@@ -999,6 +1007,7 @@ inflate_unzip_internal(STATE_PARAM transformer_state_t *xstate) | |||
999 | error_msg = "corrupted data"; | 1007 | error_msg = "corrupted data"; |
1000 | if (setjmp(error_jmp)) { | 1008 | if (setjmp(error_jmp)) { |
1001 | /* Error from deep inside zip machinery */ | 1009 | /* Error from deep inside zip machinery */ |
1010 | bb_error_msg(error_msg); | ||
1002 | n = -1; | 1011 | n = -1; |
1003 | goto ret; | 1012 | goto ret; |
1004 | } | 1013 | } |
diff --git a/testsuite/unzip.tests b/testsuite/unzip.tests index ca0a45800..d8738a3bd 100755 --- a/testsuite/unzip.tests +++ b/testsuite/unzip.tests | |||
@@ -34,6 +34,7 @@ rm foo.zip | |||
34 | testing "unzip (bad archive)" "uudecode; unzip bad.zip 2>&1; echo \$?" \ | 34 | testing "unzip (bad archive)" "uudecode; unzip bad.zip 2>&1; echo \$?" \ |
35 | "Archive: bad.zip | 35 | "Archive: bad.zip |
36 | inflating: ]3j½r«IK-%Ix | 36 | inflating: ]3j½r«IK-%Ix |
37 | unzip: corrupted data | ||
37 | unzip: inflate error | 38 | unzip: inflate error |
38 | 1 | 39 | 1 |
39 | " \ | 40 | " \ |