]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
Fix the bug which the patch for issue 249 made, which bug is that
authorMichihiro NAKAJIMA <ggcueroad@gmail.com>
Tue, 20 Mar 2012 04:14:40 +0000 (13:14 +0900)
committerMichihiro NAKAJIMA <ggcueroad@gmail.com>
Tue, 20 Mar 2012 04:17:18 +0000 (13:17 +0900)
sometimes sumcheck error hppens when listing a CAB file whose
compression type is none.
Do not consume extra bytes when the compression type is none.

libarchive/archive_read_support_format_cab.c

index d1ecd27b866e01d4a33581a1ed4183c7da7b8e21..1fe5c62f15c4148182545e82460d0317fbba6898 100644 (file)
@@ -1358,47 +1358,25 @@ cab_read_ahead_cfdata_none(struct archive_read *a, ssize_t *avail)
        struct cab *cab = (struct cab *)(a->format->data);
        struct cfdata *cfdata;
        const void *d;
-       int64_t skipped_bytes;
 
        cfdata = cab->entry_cfdata;
 
-       if (cfdata->uncompressed_avail == 0 &&
-               cfdata->read_offset > 0) {
-               /* we've already skipped some bytes before really read. */
-               skipped_bytes = cfdata->read_offset;
-               cfdata->read_offset = 0;
-               cfdata->uncompressed_bytes_remaining +=
-                       (uint16_t)skipped_bytes;
-       } else
-               skipped_bytes = 0;
-       do {
-               /*
-                * Note: '1' here is a performance optimization.
-                * Recall that the decompression layer returns a count of
-                * available bytes; asking for more than that forces the
-                * decompressor to combine reads by copying data.
-                */
-               d = __archive_read_ahead(a, 1, avail);
-               if (*avail <= 0) {
-                       *avail = truncated_error(a);
-                       return (NULL);
-               }
-               if (*avail > cfdata->uncompressed_bytes_remaining)
-                       *avail = cfdata->uncompressed_bytes_remaining;
-               cfdata->uncompressed_avail = cfdata->uncompressed_size;
-               cfdata->unconsumed = *avail;
-               cfdata->sum_ptr = d;
-               if (skipped_bytes > 0) {
-                       skipped_bytes =
-                           cab_minimum_consume_cfdata(a, skipped_bytes);
-                       if (skipped_bytes < 0) {
-                               *avail = ARCHIVE_FATAL;
-                               return (NULL);
-                       }
-                       continue;
-               }
-       } while (0);
-
+       /*
+        * Note: '1' here is a performance optimization.
+        * Recall that the decompression layer returns a count of
+        * available bytes; asking for more than that forces the
+        * decompressor to combine reads by copying data.
+        */
+       d = __archive_read_ahead(a, 1, avail);
+       if (*avail <= 0) {
+               *avail = truncated_error(a);
+               return (NULL);
+       }
+       if (*avail > cfdata->uncompressed_bytes_remaining)
+               *avail = cfdata->uncompressed_bytes_remaining;
+       cfdata->uncompressed_avail = cfdata->uncompressed_size;
+       cfdata->unconsumed = *avail;
+       cfdata->sum_ptr = d;
        return (d);
 }
 
@@ -1993,6 +1971,11 @@ archive_read_format_cab_read_data_skip(struct archive_read *a)
        if (bytes_skipped < 0)
                return (ARCHIVE_FATAL);
 
+       /* If the compression type is none(uncompressed), we've already
+        * consumed data as much as the current entry size. */
+       if (cab->entry_cffolder->comptype == COMPTYPE_NONE)
+               cab->entry_cfdata->unconsumed = 0;
+
        /* This entry is finished and done. */
        cab->end_of_entry_cleanup = cab->end_of_entry = 1;
        return (ARCHIVE_OK);