aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLasse Collin <lasse.collin@tukaani.org>2011-04-11 13:59:50 +0300
committerLasse Collin <lasse.collin@tukaani.org>2011-04-11 13:59:50 +0300
commitd1199274758049fc523d98c5b860ff814a799eec (patch)
treea94a713194803c300d18b848ddffb89fa463483b
parentliblzma: Fix API docs to mention LZMA_UNSUPPORTED_CHECK. (diff)
downloadxz-d1199274758049fc523d98c5b860ff814a799eec.tar.xz
liblzma: Don't create an empty Block in lzma_stream_buffer_encode().
Empty Block was created if the input buffer was empty. Empty Block wastes a few bytes of space, but more importantly it triggers a bug in XZ Utils 5.0.1 and older when trying to decompress such a file. 5.0.1 and older consider such files to be corrupt. I thought that no encoder creates empty Blocks when releasing 5.0.2 but I was wrong.
-rw-r--r--src/liblzma/common/stream_buffer_encoder.c20
1 files changed, 13 insertions, 7 deletions
diff --git a/src/liblzma/common/stream_buffer_encoder.c b/src/liblzma/common/stream_buffer_encoder.c
index dd23c9af..2450ee2e 100644
--- a/src/liblzma/common/stream_buffer_encoder.c
+++ b/src/liblzma/common/stream_buffer_encoder.c
@@ -84,26 +84,32 @@ lzma_stream_buffer_encode(lzma_filter *filters, lzma_check check,
out_pos += LZMA_STREAM_HEADER_SIZE;
- // Block
+ // Encode a Block but only if there is at least one byte of input.
lzma_block block = {
.version = 0,
.check = check,
.filters = filters,
};
- return_if_error(lzma_block_buffer_encode(&block, allocator,
- in, in_size, out, &out_pos, out_size));
+ if (in_size > 0)
+ return_if_error(lzma_block_buffer_encode(&block, allocator,
+ in, in_size, out, &out_pos, out_size));
// Index
{
- // Create an Index with one Record.
+ // Create an Index. It will have one Record if there was
+ // at least one byte of input to encode. Otherwise the
+ // Index will be empty.
lzma_index *i = lzma_index_init(allocator);
if (i == NULL)
return LZMA_MEM_ERROR;
- lzma_ret ret = lzma_index_append(i, allocator,
- lzma_block_unpadded_size(&block),
- block.uncompressed_size);
+ lzma_ret ret = LZMA_OK;
+
+ if (in_size > 0)
+ ret = lzma_index_append(i, allocator,
+ lzma_block_unpadded_size(&block),
+ block.uncompressed_size);
// If adding the Record was successful, encode the Index
// and get its size which will be stored into Stream Footer.