Skip to content

Discard compressed input buffer on backward gzip seek - #258

Merged
rhpvorderman merged 2 commits into
pycompression:developfrom
glinkinvd:fix-gzip-backward-seek
Oct 13, 2026
Merged

rhpvorderman merged 2 commits into
pycompression:developfrom
glinkinvd:fix-gzip-backward-seek

Conversation

@glinkinvd

Copy link
Copy Markdown
Contributor

Reading an igzip.open stream after a backward seek can raise BadGzipFile, even when the archive was written by standard gzip. GzipReader_seek rewinds the underlying file and resets the inflater, but retains pointers to compressed data buffered before the seek. That stale data can be interpreted as a new gzip header.

Reset both compressed-input pointers after successfully rewinding the file, and release the Python return value from the underlying seek call. Add seven regression checks using standard gzip and igzip writers, repeated and random data, multiple forward/backward positions, and the raw reader.

A public-API reproducer uses data = b'hello world' * 24000, reads 400 bytes after seek(12345), then calls seek(0) and read().

Validation on Linux x86_64 / CPython 3.14.7:

  • Full suite on this branch: 9450 passed, 6 skipped.
  • Both proposed fixes together, with static and dynamic ISA-L linking: 9605 passed, 6 skipped in each run.
  • Both fixes together under AddressSanitizer and LeakSanitizer: 9605 passed, 6 skipped, exit 0.
  • Full-tree flake8 and mypy passed for the combined tree.

The sanitizer run used CPython 3.14 with PYTHONMALLOC=malloc, detect_leaks=1, and pytest plugin autoload disabled; pytest-timeout was explicitly enabled. It was not the debug-interpreter tox environment. Skips are the existing big-memory and unsupported copy scenarios.

Checklist

  • Pull request details were added to CHANGELOG.rst
  • Documentation was reviewed; no API changes require an update

@rhpvorderman
rhpvorderman merged commit b6f1258 into pycompression:develop Oct 13, 2026
17 of 20 checks passed
@rhpvorderman

Copy link
Copy Markdown
Collaborator

Thanks a lot for reporting and fixing these bugs!

I will bump the python versions as well as make sure the address sanitizer does not find any problems. Then I think it is time to release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants