gh-133998: Fix tarfile error on out-of-range mtime in streaming gzip mode - #151828
harjothkhara wants to merge 3 commits into
Conversation
…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).
|
@serhiy-storchaka you flagged the same out-of-range mtime bug in |
|
This PR is stale because it has been open for 90 days with no activity. |
vstinner
left a comment
There was a problem hiding this comment.
LGTM. Thanks for tests which cover all code paths. The Changelog entry describes well the fix. And tarfile behaves as gzip (same code in fact). So all good!
|
Oh, test_os.test_posix failed in the MSan job: MSan logs: Does MSan change excve() behavior? |
|
So far, I failed to reproduce the issue on Fedora 44 with clang version 22.1.8. The GHA CI uses |
|
I created #158868 for the MSan failure. |
A streaming gzip tarball (
"w|gz") with an out-of-range mtime (negative, or a clock past 2106) raisesstruct.errorinstead 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:gzpath usesGzipFile, so it was already fine.Added tests for the boundary and bad-clock cases.
AI-assisted; I reviewed it and can explain it.
2106-02-07T06:28:15#133998