Skip to content

Fix the mtime attribute of IGzipFile for a modification time of 0 - #310

Open
ptweezy wants to merge 1 commit into
pycompression:developfrom
ptweezy:gzipreader-mtime-zero
Open

ptweezy wants to merge 1 commit into
pycompression:developfrom
ptweezy:gzipreader-mtime-zero

Conversation

@ptweezy

@ptweezy ptweezy commented Oct 28, 2026

Copy link
Copy Markdown
Contributor

After reading a gzip file whose header has a modification time of 0, IGzipFile.mtime is None. gzip.GzipFile gives 0, and so did python-isal 1.3.0. The getter of _GzipReader._last_mtime returns None when the stored time is 0. That check came with the C reader in 1.4.0 (25e1449), where _last_mtime starts at 0, and it makes mtime None before the first read, as test_mtime in the CPython tests expects. It cannot tell a time of 0 from a reader that has not read a header yet.

RFC 1952 says that an MTIME of 0 means no time stamp is available, but the gzip documentation describes mtime after a read as an integer, and gzip.GzipFile returns 0. A modification time of 0 is common. gzip -n, python -m isal.igzip -n, and igzip_threaded writers write it, and so does gzip.compress() by default on Python 3.14. For example, on Python 3.14:

>>> import gzip, io
>>> from isal import igzip
>>> f = igzip.IGzipFile(fileobj=io.BytesIO(gzip.compress(b"data")))
>>> f.read(), f.mtime
(b'data', None)

This PR adds a flag to _GzipReader that is set when it reads the first header, and the getter checks the flag. mtime is still None before the first read. The new test_igzipfile_mtime fails on develop for a time of 0.

Checklist

  • Pull request details were added to CHANGELOG.rst
  • Documentation was updated (if needed)

The getter of _last_mtime returned None when the stored time was 0, so a gzip header with a modification time of 0 read as None. Keep a separate flag that is set when the first header is read.

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