Fix potential IndexOutOfBounds Exception

Fix potential IndexOutOfBounds Exception
This commit is contained in:
2025-09-16 10:00:40 -06:00
committed by GitHub
parent 0d403225a4
commit 18b307c859

13
main.py
View File

@@ -142,18 +142,9 @@ class BZZCompressor:
# Here we copy bit by bit from earlier in the output buffer. # Here we copy bit by bit from earlier in the output buffer.
# we use this instead of index slicing since the slice could lead to # we use this instead of index slicing since the slice could lead to
# data we are currently copying into the buffer # data we are currently copying into the buffer
start_index = len(output_buffer) - int(displacement.to01(), 2)
for i in range(length): for i in range(length):
out_index = len(output_buffer) output_buffer.append(output_buffer[start_index + i])
copy_index = out_index - int(displacement.to01(), 2)
# This shouldn't happen
if copy_index < 0:
print(
"Error decompressing file. copy_index is out of range"
)
return
output_buffer.append(output_buffer[copy_index])
num_flags = bitarray(bin(int(num_flags.to01(), 2) - 1)[2:].zfill(24)) num_flags = bitarray(bin(int(num_flags.to01(), 2) - 1)[2:].zfill(24))