1
0
Fork 0
mirror of https://git.tukaani.org/xz.git synced 2024-04-04 12:36:23 +02:00

The LZMA2 decoder fix introduced a bug to LZ decoder,

which made LZ decoder return too early after dictionary
reset. This fixes it.
This commit is contained in:
Lasse Collin 2008-12-15 14:26:52 +02:00
parent f9f2d1e743
commit 17781c2c20

View file

@ -84,14 +84,14 @@ decode_buffer(lzma_coder *coder,
// where to start copying to the out[] buffer. // where to start copying to the out[] buffer.
const size_t dict_start = coder->dict.pos; const size_t dict_start = coder->dict.pos;
// Calculate how much we allow the process() function to // Calculate how much we allow coder->lz.code() to decode.
// decode. It must not decode past the end of the dictionary // It must not decode past the end of the dictionary
// buffer, and we don't want it to decode more than is // buffer, and we don't want it to decode more than is
// actually needed to fill the out[] buffer. // actually needed to fill the out[] buffer.
coder->dict.limit = coder->dict.pos + MIN(out_size - *out_pos, coder->dict.limit = coder->dict.pos + MIN(out_size - *out_pos,
coder->dict.size - coder->dict.pos); coder->dict.size - coder->dict.pos);
// Call the process() function to do the actual decoding. // Call the coder->lz.code() to do the actual decoding.
const lzma_ret ret = coder->lz.code( const lzma_ret ret = coder->lz.code(
coder->lz.coder, &coder->dict, coder->lz.coder, &coder->dict,
in, in_pos, in_size); in, in_pos, in_size);
@ -104,15 +104,28 @@ decode_buffer(lzma_coder *coder,
copy_size); copy_size);
*out_pos += copy_size; *out_pos += copy_size;
// Reset the dictionary if so requested by process(). // Reset the dictionary if so requested by coder->lz.code().
if (coder->dict.need_reset) if (coder->dict.need_reset) {
lz_decoder_reset(coder); lz_decoder_reset(coder);
// Return if everything got decoded or an error occurred, or // Since we reset dictionary, we don't check if
// if there's no more data to decode. // dictionary became full.
if (ret != LZMA_OK || *out_pos == out_size if (ret != LZMA_OK || *out_pos == out_size)
|| coder->dict.pos < coder->dict.size) return ret;
return ret; } else {
// Return if everything got decoded or an error
// occurred, or if there's no more data to decode.
//
// Note that detecting if there's something to decode
// is done by looking if dictionary become full
// instead of looking if *in_pos == in_size. This
// is because it is possible that all the input was
// consumed already but some data is pending to be
// written to the dictionary.
if (ret != LZMA_OK || *out_pos == out_size
|| coder->dict.pos < coder->dict.size)
return ret;
}
} }
} }