diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2016-04-18 01:14:05 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2016-04-18 01:14:05 +0200 |
commit | bca4deee8393395f77630ad320c306d06ea186ed (patch) | |
tree | f5513ed12f015cdf8d2c5d35d1753a6f54e9a6f0 /archival/unzip.c | |
parent | 0ccf52a9fb9fa2f76eacbb6f1ef8419220557a40 (diff) | |
download | busybox-w32-bca4deee8393395f77630ad320c306d06ea186ed.tar.gz busybox-w32-bca4deee8393395f77630ad320c306d06ea186ed.tar.bz2 busybox-w32-bca4deee8393395f77630ad320c306d06ea186ed.zip |
unzip: fix percent overflow; show "stored" files properly
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to '')
-rw-r--r-- | archival/unzip.c | 35 |
1 files changed, 29 insertions, 6 deletions
diff --git a/archival/unzip.c b/archival/unzip.c index b0a6ca836..7bf51f466 100644 --- a/archival/unzip.c +++ b/archival/unzip.c | |||
@@ -263,15 +263,18 @@ static uint32_t read_next_cdf(uint32_t cdf_offset, cdf_header_t *cdf_ptr) | |||
263 | xlseek(zip_fd, cdf_offset + 4, SEEK_SET); | 263 | xlseek(zip_fd, cdf_offset + 4, SEEK_SET); |
264 | xread(zip_fd, cdf_ptr->raw, CDF_HEADER_LEN); | 264 | xread(zip_fd, cdf_ptr->raw, CDF_HEADER_LEN); |
265 | FIX_ENDIANNESS_CDF(*cdf_ptr); | 265 | FIX_ENDIANNESS_CDF(*cdf_ptr); |
266 | dbg("file_name_length:%u", (unsigned)cdf_ptr->formatted.file_name_length); | 266 | dbg(" file_name_length:%u extra_field_length:%u file_comment_length:%u", |
267 | dbg("extra_field_length:%u", (unsigned)cdf_ptr->formatted.extra_field_length); | 267 | (unsigned)cdf_ptr->formatted.file_name_length, |
268 | dbg("file_comment_length:%u", (unsigned)cdf_ptr->formatted.file_comment_length); | 268 | (unsigned)cdf_ptr->formatted.extra_field_length, |
269 | (unsigned)cdf_ptr->formatted.file_comment_length | ||
270 | ); | ||
269 | cdf_offset += 4 + CDF_HEADER_LEN | 271 | cdf_offset += 4 + CDF_HEADER_LEN |
270 | + cdf_ptr->formatted.file_name_length | 272 | + cdf_ptr->formatted.file_name_length |
271 | + cdf_ptr->formatted.extra_field_length | 273 | + cdf_ptr->formatted.extra_field_length |
272 | + cdf_ptr->formatted.file_comment_length; | 274 | + cdf_ptr->formatted.file_comment_length; |
273 | } | 275 | } |
274 | 276 | ||
277 | dbg("Returning file position to 0x%"OFF_FMT"x", org); | ||
275 | xlseek(zip_fd, org, SEEK_SET); | 278 | xlseek(zip_fd, org, SEEK_SET); |
276 | return cdf_offset; | 279 | return cdf_offset; |
277 | }; | 280 | }; |
@@ -614,6 +617,11 @@ int unzip_main(int argc, char **argv) | |||
614 | bb_error_msg_and_die("can't find file table"); | 617 | bb_error_msg_and_die("can't find file table"); |
615 | } | 618 | } |
616 | #endif | 619 | #endif |
620 | dbg("File cmpsize:0x%x extra_len:0x%x ucmpsize:0x%x", | ||
621 | (unsigned)zip_header.formatted.cmpsize, | ||
622 | (unsigned)zip_header.formatted.extra_len, | ||
623 | (unsigned)zip_header.formatted.ucmpsize | ||
624 | ); | ||
617 | 625 | ||
618 | /* Read filename */ | 626 | /* Read filename */ |
619 | free(dst_fn); | 627 | free(dst_fn); |
@@ -646,16 +654,31 @@ int unzip_main(int argc, char **argv) | |||
646 | (dostime & 0x0000f800) >> 11, | 654 | (dostime & 0x0000f800) >> 11, |
647 | (dostime & 0x000007e0) >> 5, | 655 | (dostime & 0x000007e0) >> 5, |
648 | dst_fn); | 656 | dst_fn); |
649 | total_usize += zip_header.formatted.ucmpsize; | ||
650 | } else { | 657 | } else { |
651 | unsigned long percents = zip_header.formatted.ucmpsize - zip_header.formatted.cmpsize; | 658 | unsigned long percents = zip_header.formatted.ucmpsize - zip_header.formatted.cmpsize; |
659 | if ((int32_t)percents < 0) | ||
660 | percents = 0; /* happens if ucmpsize < cmpsize */ | ||
652 | percents = percents * 100; | 661 | percents = percents * 100; |
653 | if (zip_header.formatted.ucmpsize) | 662 | if (zip_header.formatted.ucmpsize) |
654 | percents /= zip_header.formatted.ucmpsize; | 663 | percents /= zip_header.formatted.ucmpsize; |
655 | // " Length Method Size Ratio Date Time CRC-32 Name\n" | 664 | // " Length Method Size Ratio Date Time CRC-32 Name\n" |
656 | // "-------- ------ ------- ----- ---- ---- ------ ----" | 665 | // "-------- ------ ------- ----- ---- ---- ------ ----" |
657 | printf( "%8u Defl:N" "%9u%4u%% %02u-%02u-%02u %02u:%02u %08x %s\n", | 666 | printf( "%8u %s" "%9u%4u%% %02u-%02u-%02u %02u:%02u %08x %s\n", |
658 | (unsigned)zip_header.formatted.ucmpsize, | 667 | (unsigned)zip_header.formatted.ucmpsize, |
668 | zip_header.formatted.method == 0 ? "Stored" : "Defl:N", /* Defl is method 8 */ | ||
669 | /* TODO: show other methods? | ||
670 | * 1 - Shrunk | ||
671 | * 2 - Reduced with compression factor 1 | ||
672 | * 3 - Reduced with compression factor 2 | ||
673 | * 4 - Reduced with compression factor 3 | ||
674 | * 5 - Reduced with compression factor 4 | ||
675 | * 6 - Imploded | ||
676 | * 7 - Reserved for Tokenizing compression algorithm | ||
677 | * 9 - Deflate64 | ||
678 | * 10 - PKWARE Data Compression Library Imploding | ||
679 | * 11 - Reserved by PKWARE | ||
680 | * 12 - BZIP2 | ||
681 | */ | ||
659 | (unsigned)zip_header.formatted.cmpsize, | 682 | (unsigned)zip_header.formatted.cmpsize, |
660 | (unsigned)percents, | 683 | (unsigned)percents, |
661 | (dostime & 0x01e00000) >> 21, | 684 | (dostime & 0x01e00000) >> 21, |
@@ -665,9 +688,9 @@ int unzip_main(int argc, char **argv) | |||
665 | (dostime & 0x000007e0) >> 5, | 688 | (dostime & 0x000007e0) >> 5, |
666 | zip_header.formatted.crc32, | 689 | zip_header.formatted.crc32, |
667 | dst_fn); | 690 | dst_fn); |
668 | total_usize += zip_header.formatted.ucmpsize; | ||
669 | total_size += zip_header.formatted.cmpsize; | 691 | total_size += zip_header.formatted.cmpsize; |
670 | } | 692 | } |
693 | total_usize += zip_header.formatted.ucmpsize; | ||
671 | i = 'n'; | 694 | i = 'n'; |
672 | } else if (dst_fd == STDOUT_FILENO) { | 695 | } else if (dst_fd == STDOUT_FILENO) { |
673 | /* Extracting to STDOUT */ | 696 | /* Extracting to STDOUT */ |