]> wimlib.net Git - wimlib/commitdiff
Require size_in_wim == uncompressed_size for uncompressed resources
authorEric Biggers <ebiggers3@gmail.com>
Sat, 30 May 2015 20:48:03 +0000 (15:48 -0500)
committerEric Biggers <ebiggers3@gmail.com>
Sat, 30 May 2015 20:48:03 +0000 (15:48 -0500)
It required quite a bit of extra code to handle this case, which really
should just be considered invalid.

src/blob_table.c
src/resource.c

index 08859c42787baa5147a398bdacdecae579f69275..4ec6cd931b9fc899367118fa040f55c8b134ee6b 100644 (file)
@@ -953,27 +953,13 @@ read_blob_table(WIMStruct *wim)
                                        goto out;
                        }
 
                                        goto out;
                        }
 
-                       /* How to handle an uncompressed resource with its
-                        * uncompressed size different from its compressed size?
-                        *
-                        * Based on a simple test, WIMGAPI seems to handle this
-                        * as follows:
-                        *
-                        * if (size_in_wim > uncompressed_size) {
-                        *      Ignore uncompressed_size; use size_in_wim
-                        *      instead.
-                        * } else {
-                        *      Honor uncompressed_size, but treat the part of
-                        *      the file data above size_in_wim as all zeros.
-                        * }
-                        *
-                        * So we will do the same.  */
-                       if (unlikely(!(reshdr.flags &
-                                      WIM_RESHDR_FLAG_COMPRESSED) &&
-                                    (reshdr.size_in_wim >
-                                     reshdr.uncompressed_size)))
+                       if (unlikely(!(reshdr.flags & WIM_RESHDR_FLAG_COMPRESSED) &&
+                                    (reshdr.size_in_wim != reshdr.uncompressed_size)))
                        {
                        {
-                               reshdr.uncompressed_size = reshdr.size_in_wim;
+                               ERROR("Uncompressed resource has "
+                                     "size_in_wim != uncompressed_size");
+                               ret = WIMLIB_ERR_INVALID_LOOKUP_TABLE_ENTRY;
+                               goto out;
                        }
 
                        /* Set up a resource descriptor for this blob.  */
                        }
 
                        /* Set up a resource descriptor for this blob.  */
index 134821971a6b3b20e4b6d79f520be219ab6c1dbc..e2a39991e2e4115a121134a67ac1046cbff22f8f 100644 (file)
@@ -554,28 +554,6 @@ read_error:
        goto out_free_memory;
 }
 
        goto out_free_memory;
 }
 
-static int
-fill_zeroes(u64 size, consume_data_callback_t cb, void *cb_ctx)
-{
-       if (unlikely(size)) {
-               u8 buf[min(size, BUFFER_SIZE)];
-
-               memset(buf, 0, sizeof(buf));
-
-               do {
-                       size_t len;
-                       int ret;
-
-                       len = min(size, BUFFER_SIZE);
-                       ret = cb(buf, len, cb_ctx);
-                       if (ret)
-                               return ret;
-                       size -= len;
-               } while (size);
-       }
-       return 0;
-}
-
 /* Read raw data from a file descriptor at the specified offset, feeding the
  * data it in chunks into the specified callback function.  */
 static int
 /* Read raw data from a file descriptor at the specified offset, feeding the
  * data it in chunks into the specified callback function.  */
 static int
@@ -668,37 +646,9 @@ read_partial_wim_resource(const struct wim_resource_descriptor *rdesc,
                return read_compressed_wim_resource(rdesc, &range, 1,
                                                    cb, cb_ctx);
        } else {
                return read_compressed_wim_resource(rdesc, &range, 1,
                                                    cb, cb_ctx);
        } else {
-               /* Reading uncompressed resource.  For completeness, handle the
-                * weird case where size_in_wim < uncompressed_size.  */
-
-               u64 read_size;
-               u64 zeroes_size;
-               int ret;
-
-               if (likely(offset + size <= rdesc->size_in_wim) ||
-                   rdesc->is_pipable)
-               {
-                       read_size = size;
-                       zeroes_size = 0;
-               } else {
-                       if (offset >= rdesc->size_in_wim) {
-                               read_size = 0;
-                               zeroes_size = size;
-                       } else {
-                               read_size = rdesc->size_in_wim - offset;
-                               zeroes_size = offset + size - rdesc->size_in_wim;
-                       }
-               }
-
-               ret = read_raw_file_data(&rdesc->wim->in_fd,
-                                        rdesc->offset_in_wim + offset,
-                                        read_size,
-                                        cb,
-                                        cb_ctx);
-               if (ret)
-                       return ret;
-
-               return fill_zeroes(zeroes_size, cb, cb_ctx);
+               return read_raw_file_data(&rdesc->wim->in_fd,
+                                         rdesc->offset_in_wim + offset,
+                                         size, cb, cb_ctx);
        }
 }
 
        }
 }