Skip to content

gh-133998: Fix tarfile error on out-of-range mtime in streaming gzip mode#151828

Open
harjothkhara wants to merge 1 commit into
python:mainfrom
harjothkhara:gh-133998-tarfile-mtime
Open

gh-133998: Fix tarfile error on out-of-range mtime in streaming gzip mode#151828
harjothkhara wants to merge 1 commit into
python:mainfrom
harjothkhara:gh-133998-tarfile-mtime

Conversation

@harjothkhara

@harjothkhara harjothkhara commented Jun 21, 2026

Copy link
Copy Markdown
Contributor

A streaming gzip tarball ("w|gz") with an out-of-range mtime (negative, or a clock past 2106) raises struct.error instead of writing the file.

gzip already clamps these to 0 (GH-134278); this does the same for tarfile's streaming path. The non-streaming w:gz path uses GzipFile, so it was already fine.

Added tests for the boundary and bad-clock cases.

AI-assisted; I reviewed it and can explain it.

…rites

tarfile.open(..., "w|gz", mtime=...) packed mtime into the gzip header's
32-bit field with no range check, so a value < 0 or >= 2**32 raised
struct.error. Mirror the merged gzip fix: substitute 0 for out-of-range
values and coerce to int (RFC 1952), so floats and out-of-range system
clocks behave the same as in gzip and the non-streaming "w:gz" path
(which already delegates to GzipFile and was unaffected).
@harjothkhara harjothkhara changed the title gh-133998: Clamp out-of-range mtime in tarfile streaming gzip writes gh-133998: Fix tarfile error on out-of-range mtime in streaming gzip mode Jun 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant