/* Read the chunk and feed data to the callback
* function. */
- u8 *cb_buf;
+ u8 *read_buf;
+
+ if (chunk_csize == chunk_usize || raw_chunks_mode)
+ read_buf = ubuf;
+ else
+ read_buf = cbuf;
ret = full_pread(in_fd,
- cbuf,
+ read_buf,
chunk_csize,
cur_read_offset);
if (ret)
goto read_error;
- if (chunk_csize != chunk_usize && !raw_chunks_mode) {
+ if (read_buf == cbuf) {
DEBUG("Decompressing chunk %"PRIu64" "
"(csize=%"PRIu64" usize=%"PRIu64"",
i, chunk_csize, chunk_usize);
errno = EINVAL;
goto out_free_memory;
}
- cb_buf = ubuf;
- } else {
- /* Raw chunks requested, or data stored
- * uncompressed. */
- cb_buf = cbuf;
}
cur_read_offset += chunk_csize;
size = end - start;
if (raw_chunks_mode)
- ret = (*cb)(&cb_buf[0], chunk_csize, cb_ctx);
+ ret = (*cb)(&ubuf[0], chunk_csize, cb_ctx);
else
- ret = (*cb)(&cb_buf[start], size, cb_ctx);
+ ret = (*cb)(&ubuf[start], size, cb_ctx);
if (ret)
goto out_free_memory;
wimlib_assert(offset + size <= rspec->size_in_wim);
} else if (flags & WIMLIB_READ_RESOURCE_FLAG_RAW_CHUNKS) {
wimlib_assert(offset == 0);
- wimlib_assert(offset == rspec->uncompressed_size);
+ wimlib_assert(size == rspec->uncompressed_size);
} else {
wimlib_assert(offset + size >= offset);
wimlib_assert(offset + size <= rspec->uncompressed_size);
/* Translates a WIM resource header from the on-disk format into an in-memory
* format. */
-int
+void
get_wim_reshdr(const struct wim_reshdr_disk *disk_reshdr,
struct wim_reshdr *reshdr)
{
((u64)disk_reshdr->size_in_wim[6] << 48));
reshdr->uncompressed_size = le64_to_cpu(disk_reshdr->uncompressed_size);
reshdr->flags = disk_reshdr->flags;
-
- /* Avoid possible overflows. */
- if (reshdr->offset_in_wim & 0xc000000000000000ULL)
- return WIMLIB_ERR_INVALID_LOOKUP_TABLE_ENTRY;
-
- if (reshdr->uncompressed_size & 0xc000000000000000ULL)
- return WIMLIB_ERR_INVALID_LOOKUP_TABLE_ENTRY;
-
return 0;
}