]> git.ipfire.org Git - thirdparty/xz.git/commitdiff
liblzma: Fix missing normalization in rc_encode_dummy().
authorLasse Collin <lasse.collin@tukaani.org>
Thu, 14 Jan 2021 18:57:11 +0000 (20:57 +0200)
committerLasse Collin <lasse.collin@tukaani.org>
Thu, 14 Jan 2021 18:57:11 +0000 (20:57 +0200)
Without this fix it could attempt to create too much output.

src/liblzma/rangecoder/range_encoder.h

index 1bcfd7a5ba137d7c277125c2b48258caca4f4b8b..5e2afafe1f67beab7de8e1d0ac5ab1510a4dd8bf 100644 (file)
@@ -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: {