diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2007-01-10 20:50:04 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2007-01-10 20:50:04 +0000 |
commit | 7573541f74ab83e6501adf1a67210c8f99a6d885 (patch) | |
tree | 008efc06a84dc7510c4a033465b18a8975b86d69 | |
parent | bbe514683a43e81cab1d5ccc0436b9aaf984294b (diff) | |
download | busybox-w32-7573541f74ab83e6501adf1a67210c8f99a6d885.tar.gz busybox-w32-7573541f74ab83e6501adf1a67210c8f99a6d885.tar.bz2 busybox-w32-7573541f74ab83e6501adf1a67210c8f99a6d885.zip |
fix bug 1146 (gunzip breakage introduced by me --vda)
-rw-r--r-- | archival/libunarchive/decompress_unzip.c | 36 |
1 files changed, 19 insertions, 17 deletions
diff --git a/archival/libunarchive/decompress_unzip.c b/archival/libunarchive/decompress_unzip.c index 424fe5190..f330a11ad 100644 --- a/archival/libunarchive/decompress_unzip.c +++ b/archival/libunarchive/decompress_unzip.c | |||
@@ -98,6 +98,8 @@ typedef struct state_t { | |||
98 | huft_t *inflate_codes_td; | 98 | huft_t *inflate_codes_td; |
99 | unsigned inflate_codes_bl; | 99 | unsigned inflate_codes_bl; |
100 | unsigned inflate_codes_bd; | 100 | unsigned inflate_codes_bd; |
101 | unsigned inflate_codes_nn; /* length and index for copy */ | ||
102 | unsigned inflate_codes_dd; | ||
101 | smallint resume_copy; | 103 | smallint resume_copy; |
102 | 104 | ||
103 | /* private data of inflate_get_next_window() */ | 105 | /* private data of inflate_get_next_window() */ |
@@ -132,6 +134,8 @@ typedef struct state_t { | |||
132 | #define inflate_codes_td (S()inflate_codes_td ) | 134 | #define inflate_codes_td (S()inflate_codes_td ) |
133 | #define inflate_codes_bl (S()inflate_codes_bl ) | 135 | #define inflate_codes_bl (S()inflate_codes_bl ) |
134 | #define inflate_codes_bd (S()inflate_codes_bd ) | 136 | #define inflate_codes_bd (S()inflate_codes_bd ) |
137 | #define inflate_codes_nn (S()inflate_codes_nn ) | ||
138 | #define inflate_codes_dd (S()inflate_codes_dd ) | ||
135 | #define resume_copy (S()resume_copy ) | 139 | #define resume_copy (S()resume_copy ) |
136 | #define method (S()method ) | 140 | #define method (S()method ) |
137 | #define need_another_block (S()need_another_block ) | 141 | #define need_another_block (S()need_another_block ) |
@@ -460,6 +464,8 @@ static int huft_build(unsigned *b, const unsigned n, | |||
460 | #define td inflate_codes_td | 464 | #define td inflate_codes_td |
461 | #define bl inflate_codes_bl | 465 | #define bl inflate_codes_bl |
462 | #define bd inflate_codes_bd | 466 | #define bd inflate_codes_bd |
467 | #define nn inflate_codes_nn | ||
468 | #define dd inflate_codes_dd | ||
463 | static void inflate_codes_setup(STATE_PARAM huft_t * my_tl, huft_t * my_td, const unsigned my_bl, const unsigned my_bd) | 469 | static void inflate_codes_setup(STATE_PARAM huft_t * my_tl, huft_t * my_td, const unsigned my_bl, const unsigned my_bd) |
464 | { | 470 | { |
465 | tl = my_tl; | 471 | tl = my_tl; |
@@ -510,10 +516,6 @@ static int inflate_codes(STATE_PARAM_ONLY) | |||
510 | return 1; // We have a block to read | 516 | return 1; // We have a block to read |
511 | } | 517 | } |
512 | } else { /* it's an EOB or a length */ | 518 | } else { /* it's an EOB or a length */ |
513 | /* length and index for copy */ | ||
514 | unsigned n = n; /* for gcc */ | ||
515 | unsigned d = d; /* for gcc */ | ||
516 | |||
517 | /* exit if end of block */ | 519 | /* exit if end of block */ |
518 | if (e == 15) { | 520 | if (e == 15) { |
519 | break; | 521 | break; |
@@ -521,7 +523,7 @@ static int inflate_codes(STATE_PARAM_ONLY) | |||
521 | 523 | ||
522 | /* get length of block to copy */ | 524 | /* get length of block to copy */ |
523 | bb = fill_bitbuffer(PASS_STATE bb, &k, e); | 525 | bb = fill_bitbuffer(PASS_STATE bb, &k, e); |
524 | n = t->v.n + ((unsigned) bb & mask_bits[e]); | 526 | nn = t->v.n + ((unsigned) bb & mask_bits[e]); |
525 | bb >>= e; | 527 | bb >>= e; |
526 | k -= e; | 528 | k -= e; |
527 | 529 | ||
@@ -544,40 +546,40 @@ static int inflate_codes(STATE_PARAM_ONLY) | |||
544 | bb >>= t->b; | 546 | bb >>= t->b; |
545 | k -= t->b; | 547 | k -= t->b; |
546 | bb = fill_bitbuffer(PASS_STATE bb, &k, e); | 548 | bb = fill_bitbuffer(PASS_STATE bb, &k, e); |
547 | d = w - t->v.n - ((unsigned) bb & mask_bits[e]); | 549 | dd = w - t->v.n - ((unsigned) bb & mask_bits[e]); |
548 | bb >>= e; | 550 | bb >>= e; |
549 | k -= e; | 551 | k -= e; |
550 | 552 | ||
551 | /* do the copy */ | 553 | /* do the copy */ |
552 | do_copy: | 554 | do_copy: |
553 | do { | 555 | do { |
554 | /* Was: n -= (e = (e = GUNZIP_WSIZE - ((d &= GUNZIP_WSIZE - 1) > w ? d : w)) > n ? n : e); */ | 556 | /* Was: nn -= (e = (e = GUNZIP_WSIZE - ((dd &= GUNZIP_WSIZE - 1) > w ? dd : w)) > nn ? nn : e); */ |
555 | /* Who wrote THAT?? rewritten as: */ | 557 | /* Who wrote THAT?? rewritten as: */ |
556 | d &= GUNZIP_WSIZE - 1; | 558 | dd &= GUNZIP_WSIZE - 1; |
557 | e = GUNZIP_WSIZE - (d > w ? d : w); | 559 | e = GUNZIP_WSIZE - (dd > w ? dd : w); |
558 | if (e > n) e = n; | 560 | if (e > nn) e = nn; |
559 | n -= e; | 561 | nn -= e; |
560 | 562 | ||
561 | /* copy to new buffer to prevent possible overwrite */ | 563 | /* copy to new buffer to prevent possible overwrite */ |
562 | if (w - d >= e) { /* (this test assumes unsigned comparison) */ | 564 | if (w - dd >= e) { /* (this test assumes unsigned comparison) */ |
563 | memcpy(gunzip_window + w, gunzip_window + d, e); | 565 | memcpy(gunzip_window + w, gunzip_window + dd, e); |
564 | w += e; | 566 | w += e; |
565 | d += e; | 567 | dd += e; |
566 | } else { | 568 | } else { |
567 | /* do it slow to avoid memcpy() overlap */ | 569 | /* do it slow to avoid memcpy() overlap */ |
568 | /* !NOMEMCPY */ | 570 | /* !NOMEMCPY */ |
569 | do { | 571 | do { |
570 | gunzip_window[w++] = gunzip_window[d++]; | 572 | gunzip_window[w++] = gunzip_window[dd++]; |
571 | } while (--e); | 573 | } while (--e); |
572 | } | 574 | } |
573 | if (w == GUNZIP_WSIZE) { | 575 | if (w == GUNZIP_WSIZE) { |
574 | gunzip_outbuf_count = w; | 576 | gunzip_outbuf_count = w; |
575 | resume_copy = (n != 0); | 577 | resume_copy = (nn != 0); |
576 | //flush_gunzip_window(); | 578 | //flush_gunzip_window(); |
577 | w = 0; | 579 | w = 0; |
578 | return 1; | 580 | return 1; |
579 | } | 581 | } |
580 | } while (n); | 582 | } while (nn); |
581 | resume_copy = 0; | 583 | resume_copy = 0; |
582 | } | 584 | } |
583 | } | 585 | } |