gh-133998: Fix gzip file creation when time is out of range#134278
Conversation
| however, if the current time is outside the range 00:00:00 UTC, January 1, | ||
| 1970 through 06:28:15 UTC, February 7, 2106, then the value ``0`` is used | ||
| instead. | ||
|
|
There was a problem hiding this comment.
The docs are slightly wrong now that GzipFile.__init__ will raise a ValueError if the specified value is out of range.
I know you've documented it in the docstring for __init__, but I think it's worth clarifying here since we're already in the area.
| Set mtime to 0 to generate a compressed stream that does not depend on | ||
| creation time. If mtime is omitted or None, the current time is used; | ||
| however, if the current time is outside the range 00:00:00 UTC, January | ||
| 1, 1970 through 06:28:15 UTC, February 7, 2106, then the value 0 is used | ||
| instead. |
| @@ -0,0 +1 @@ | |||
| Fix ``struct.error`` exception when creating a file with ``gzip.GzipFile()`` if the system time is outside the range 00:00:00 UTC, January 1, 1970 through 06:28:15 UTC, February 7, 2106. | |||
There was a problem hiding this comment.
I think this should also be tweaked since the behaviour of providing an out-of-range mtime has changed
serhiy-storchaka
left a comment
There was a problem hiding this comment.
Test also for 2**32-0.1.
I do not think that raising ValueError in the GzipFile constructor is right. This does not solve the problem of the user passing stat().st_mtime or time.time().
There is other occurrence of this problem in compress().
|
This PR is stale because it has been open for 30 days with no activity. |
Documentation build overview
|
|
Thanks @adang1345 for the PR, and @serhiy-storchaka for merging it 🌮🎉.. I'm working now to backport this PR to: 3.15. |
|
GH-150221 is a backport of this pull request to the 3.15 branch. |
|
|
Thanks for getting the fix over the line @serhiy-storchaka! 😊 |
…thonGH-134278) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
…thonGH-134278) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
If the system clock is set so that
time.time()falls outside of the range0through2**32-1, then creation of a GZIP-compressed file usinggzip.GzipFile()would fail with the exceptionstruct.error: 'L' format requires 0 <= number <= 4294967295. Fix this error.If the
mtimeargument togzip.GzipFile()is explicitly set to an out-of-range value, then the behavior is unchanged, and we continue raising the exception.2106-02-07T06:28:15#133998📚 Documentation preview 📚: https://cpython-previews--134278.org.readthedocs.build/