Skip to content

Commit

Permalink
[wim] Do not attempt to decompress non-compressed chunks
Browse files Browse the repository at this point in the history
A compressed WIM resource may contain individual chunks that are not
compressed.  The compressed and decompressed lengths are both
calculable from the chunk table.  The correct algorithm appears to be
to treat the chunk as non-compressed if the "compressed" length is
equal to the decompressed length.

Signed-off-by: Michael Brown <mbrown@fensystems.co.uk>
  • Loading branch information
mcb30 committed May 10, 2017
1 parent 0d8af67 commit 8ca9778
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions src/wim.c
Expand Up @@ -149,7 +149,7 @@ static int wim_chunk ( struct vdisk_file *file, struct wim_header *header,
size_t offset;
size_t next_offset;
size_t len;
ssize_t expected_out_len;
size_t expected_out_len;
ssize_t out_len;
int rc;

Expand All @@ -167,11 +167,17 @@ static int wim_chunk ( struct vdisk_file *file, struct wim_header *header,
expected_out_len = ( ( chunk >= ( chunks - 1 ) ) ?
( resource->len % WIM_CHUNK_LEN ) : WIM_CHUNK_LEN);

/* Read compressed data into a temporary buffer and decompress it */
{
/* Read possibly-compressed data */
if ( len == expected_out_len ) {

/* Chunk did not compress; read raw data */
file->read ( file, buf->data, ( resource->offset + offset ),
len );

} else {
uint8_t zbuf[len];

/* Read compressed data */
/* Read compressed data into a temporary buffer */
file->read ( file, zbuf, ( resource->offset + offset ), len );

/* Identify decompressor */
Expand All @@ -190,8 +196,8 @@ static int wim_chunk ( struct vdisk_file *file, struct wim_header *header,
out_len = decompress ( zbuf, len, NULL );
if ( out_len < 0 )
return out_len;
if ( out_len != expected_out_len ) {
DBG ( "Unexpected output length %#lx (expected %#lx)\n",
if ( ( ( size_t ) out_len ) != expected_out_len ) {
DBG ( "Unexpected output length %#lx (expected %#zx)\n",
out_len, expected_out_len );
return -1;
}
Expand Down

0 comments on commit 8ca9778

Please sign in to comment.