FIX: decode_huff off-by-one bug

This commit is contained in:
Christos Choutouridis 2026-02-15 21:19:59 +02:00
parent cd2b89bd73
commit 781cb3047f
2 changed files with 8 additions and 2 deletions

View File

@ -381,11 +381,14 @@ def decode_huff(huff_sec, huff_LUT):
while b:
N += 1
b = huff_sec[streamIndex + N]
# Skip the N leading '1' bits AND the terminating '0' delimiter.
# The encoder writes: '1'*N + '0' + <N4 bits>
streamIndex += N +1
N4 = N + 4
escape_word = huff_sec[streamIndex:streamIndex + N4]
escape_value = 2 ** N4 + int("".join(map(str, escape_word)), 2)
nTupleDec[idx] = escape_value
# We already consumed the delimiter above; now consume only N4 bits.
streamIndex += N4
# Apply signs again
nTupleDec[escIndex] *= nTupleSign[escIndex]

View File

@ -381,12 +381,15 @@ def decode_huff(huff_sec, huff_LUT):
while b:
N += 1
b = huff_sec[streamIndex + N]
streamIndex += N
# Skip the N leading '1' bits AND the terminating '0' delimiter.
# The encoder writes: '1'*N + '0' + <N4 bits>
streamIndex += N +1
N4 = N + 4
escape_word = huff_sec[streamIndex:streamIndex + N4]
escape_value = 2 ** N4 + int("".join(map(str, escape_word)), 2)
nTupleDec[idx] = escape_value
streamIndex += N4 + 1
# We already consumed the delimiter above; now consume only N4 bits.
streamIndex += N4
# Apply signs again
nTupleDec[escIndex] *= nTupleSign[escIndex]