aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLasse Collin <lasse.collin@tukaani.org>2021-01-14 20:57:11 +0200
committerLasse Collin <lasse.collin@tukaani.org>2021-01-14 20:57:11 +0200
commit421b0aa352da244075db10205cf33712f91b9835 (patch)
treed2d159edec80d5eff0be9140b5fb3b00e7e41994
parentliblzma: Add EROFS LZMA encoder and decoder. (diff)
downloadxz-421b0aa352da244075db10205cf33712f91b9835.tar.xz
liblzma: Fix missing normalization in rc_encode_dummy().
Without this fix it could attempt to create too much output.
-rw-r--r--src/liblzma/rangecoder/range_encoder.h7
1 files changed, 6 insertions, 1 deletions
diff --git a/src/liblzma/rangecoder/range_encoder.h b/src/liblzma/rangecoder/range_encoder.h
index 1bcfd7a5..5e2afafe 100644
--- a/src/liblzma/rangecoder/range_encoder.h
+++ b/src/liblzma/rangecoder/range_encoder.h
@@ -274,7 +274,7 @@ rc_encode_dummy(const lzma_range_encoder *rc, size_t out_size)
size_t pos = rc->pos;
- while (pos < rc->count) {
+ while (true) {
// Normalize
if (range < RC_TOP_VALUE) {
if (rc_shift_low_dummy(&low, &cache_size, &cache,
@@ -284,6 +284,11 @@ rc_encode_dummy(const lzma_range_encoder *rc, size_t out_size)
range <<= RC_SHIFT_BITS;
}
+ // This check is here because the normalization above must
+ // be done before flushing the last bytes.
+ if (pos == rc->count)
+ break;
+
// Encode a bit
switch (rc->symbols[pos]) {
case RC_BIT_0: {