Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Invalid lookback distance found!" when seeking backwards in specific deflate stream #40

Closed
pdjstone opened this issue Apr 26, 2024 · 3 comments
Labels
bug Something isn't working

Comments

@pdjstone
Copy link

With version 0.13.2 (and 0.13.1), I get an error when reading a specific deflate stream using the following code:

import rapidgzip
import zlib

with open('test.bin', 'rb') as fd:    
    decomp = zlib.decompressobj(-15)
    decomp_data = b''
    while len(decomp_data) < 40000000:
        data = fd.read(1024*1024)
        decomp_data += decomp.decompress(data)
    print(decomp_data[30000000])
    print(decomp_data[40000000])


with open('test.bin', 'rb') as fd:
    with rapidgzip.open(fd) as fd2:
        # If I swap the order of these seeks the error doesn't occur
        fd2.seek(40000000)
        print(fd2.read(1)[0])
        fd2.seek(30000000)
        print(fd2.read(1)[0])

I get the following output:

25
2
2
Traceback (most recent call last):
  File "rapidgzipbug.py", line 19, in <module>
    print(fd2.read(1)[0])
  File "rapidgzip.pyx", line 502, in rapidgzip._RapidgzipFile.readinto
RuntimeError: [IsalInflateWrapper][Thread 132968515372608] Decoding failed with error code -3: Invalid lookback distance found! Already decoded 4 B. Read 120 B 2 b during the failing isal_inflate from offset 22979651 B 4 b. Bit range to decode: [183837212, 201376656]. BitReader::size: 335544320. Set window size: 0 B.
@pdjstone pdjstone added the bug Something isn't working label Apr 26, 2024
@mxmlnkn
Copy link
Owner

mxmlnkn commented Apr 26, 2024

Thank you for reporting this bug! I can confirm it. It still works without error using rapidgzip 0.12.1. It happens only when seeking back because decompression can be delegated to ISA-L then. As I feared, the bug was introduced with the window / seek point compression, but the introducing commit was d03d2a2, not the very first window compression commit in 9edb3b9.

@mxmlnkn
Copy link
Owner

mxmlnkn commented Apr 26, 2024

Found the bug. I even already had an unreleased fix for it. Sorry for wasting your time by not releasing the fix, I somehow didn't have the thought to do so. The release should be done in the next hour or so (half the CI is suddenly broken for multiple obnoxious reasons) this weekend.

@mxmlnkn mxmlnkn closed this as completed Apr 27, 2024
@pdjstone
Copy link
Author

Thanks for fixing this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants