diff options
author | Lasse Collin <lasse.collin@tukaani.org> | 2008-04-24 18:38:00 +0300 |
---|---|---|
committer | Lasse Collin <lasse.collin@tukaani.org> | 2008-04-24 18:38:00 +0300 |
commit | 712cfe3ebfd24df24d8896b1315c53c3bc4369c8 (patch) | |
tree | 941130e6e7292b6f71e487a2251d927cdb1002ce /src/liblzma/lz/lz_encoder.c | |
parent | Fix fastpos problem in Makefile.am when built with --enable-small. (diff) | |
download | xz-712cfe3ebfd24df24d8896b1315c53c3bc4369c8.tar.xz |
Fix data corruption in LZ encoder with LZMA_SYNC_FLUSH.
Diffstat (limited to 'src/liblzma/lz/lz_encoder.c')
-rw-r--r-- | src/liblzma/lz/lz_encoder.c | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/src/liblzma/lz/lz_encoder.c b/src/liblzma/lz/lz_encoder.c index 43e6d3b4..488095ca 100644 --- a/src/liblzma/lz/lz_encoder.c +++ b/src/liblzma/lz/lz_encoder.c @@ -188,6 +188,7 @@ lzma_lz_encoder_reset(lzma_lz_encoder *lz, lzma_allocator *allocator, lz->read_pos = 0; lz->read_limit = 0; lz->write_pos = 0; + lz->pending = 0; ////////////////// @@ -443,6 +444,21 @@ fill_window(lzma_coder *coder, lzma_allocator *allocator, const uint8_t *in, if (ret == LZMA_OK && coder->lz.uncompressed_size == 0) coder->lz.sequence = SEQ_FINISH; + // Restart the match finder after finished LZMA_SYNC_FLUSH. + if (coder->lz.pending > 0 + && coder->lz.read_pos < coder->lz.read_limit) { + // Match finder may update coder->pending and expects it to + // start from zero, so use a temporary variable. + const size_t pending = coder->lz.pending; + coder->lz.pending = 0; + + // Rewind read_pos so that the match finder can hash + // the pending bytes. + assert(coder->lz.read_pos >= pending); + coder->lz.read_pos -= pending; + coder->lz.skip(&coder->lz, pending); + } + return ret; } |