Skip to content

Discard compressed input buffer on backward gzip seek - #258

Open
glinkinvd wants to merge 1 commit into
pycompression:developfrom
glinkinvd:fix-gzip-backward-seek
Open

glinkinvd wants to merge 1 commit into
pycompression:developfrom
glinkinvd:fix-gzip-backward-seek

Conversation

@glinkinvd

Copy link
Copy Markdown

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

This branch has not been deployed

No deployments
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.

1 participant