Patch from Felipe Kellermann, fix endless loop when first > last and
[oweals/busybox.git] / archival / unzip.c
index f2d7f491865368eff5d55e8dc3037274fe1b995e..eea2f5438b67563a7b8371835dc78c70e89df3fb 100644 (file)
  *
  */
 
-/* For reference to format see http://www.pkware.com/support/appnote.html */
+/* For reference see
+ * http://www.pkware.com/products/enterprise/white_papers/appnote.txt
+ * http://www.info-zip.org/pub/infozip/doc/appnote-iz-latest.zip
+ */
 
 /* TODO Endian issues, exclude, should we accept input from stdin ? */
 
@@ -135,7 +138,7 @@ extern int unzip_main(int argc, char **argv)
        }
 
        if (*argv[optind] == '-') {
-               archive_handle->src_fd = fileno(stdin);
+               archive_handle->src_fd = STDIN_FILENO;
                archive_handle->seek = seek_by_char;
        } else {
                archive_handle->src_fd = bb_xopen(argv[optind++], O_RDONLY);
@@ -199,7 +202,8 @@ extern int unzip_main(int argc, char **argv)
                        archive_handle->action_data(archive_handle);
                } else {
                        dst_fd = bb_xopen(archive_handle->file_header->name, O_WRONLY | O_CREAT);
-                       inflate(archive_handle->src_fd, dst_fd);
+                       inflate_init(zip_header.formated.cmpsize);
+                       inflate_unzip(archive_handle->src_fd, dst_fd);
                        close(dst_fd);
                        chmod(archive_handle->file_header->name, archive_handle->file_header->mode);
 
@@ -227,10 +231,8 @@ extern int unzip_main(int argc, char **argv)
                /* Data descriptor section */
                if (zip_header.formated.flags & 4) {
                        /* skip over duplicate crc, compressed size and uncompressed size */
-                       unsigned short i;
-                       for (i = 0; i != 12; i++) {
-                               archive_xread_char(archive_handle);
-                       }
+                       unsigned char data_description[12];
+                       archive_xread_all(archive_handle, data_description, 12);
                        archive_handle->offset += 12;
                }
        }