From: Eric Biggers Date: Sat, 31 May 2014 00:34:34 +0000 (-0500) Subject: Revert "lzx-compress.c: Simplify calculation of position footer" X-Git-Tag: v1.7.0~71 X-Git-Url: https://wimlib.net/git/?a=commitdiff_plain;h=cf7090dcba4736f4ea56f272b5e0152a8a0a70b5;p=wimlib Revert "lzx-compress.c: Simplify calculation of position footer" This reverts commit 3adc1ac1ebe221427857d8f6fd06cfb823b4bea6. If the position footer is unconditionally calculated as the match offset minus the position base value, the (ultimately unused) position footer for repeat matches can overflow the number of bits in which it is stored in the intermediate representation used by this implementation. For now, use the old version, which would set the position footers of repeat matches to 0. --- diff --git a/src/lzx-compress.c b/src/lzx-compress.c index 5246e1a1..360ee9c4 100644 --- a/src/lzx-compress.c +++ b/src/lzx-compress.c @@ -958,8 +958,8 @@ lzx_tally_match(unsigned match_len, unsigned match_offset, /* The match offset shall be encoded as a position slot (itself encoded * as part of the main symbol) and a position footer. */ position_slot = lzx_get_position_slot(match_offset, queue); - position_footer = (match_offset + LZX_OFFSET_OFFSET) - - lzx_position_base[position_slot]; + position_footer = (match_offset + LZX_OFFSET_OFFSET) & + ((1U << lzx_get_num_extra_bits(position_slot)) - 1); /* The match length shall be encoded as a length header (itself encoded * as part of the main symbol) and an optional length footer. */