Skip to content

Commit

Permalink
Fixed pre-1980 file timestamps raising ValueError
Browse files Browse the repository at this point in the history
Fixes #418.
  • Loading branch information
agronholm committed Oct 20, 2022
1 parent 88f02bc commit ef6b402
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
3 changes: 3 additions & 0 deletions docs/news.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ Release Notes
values) is now delegated to ``setuptools>=57.0.0`` (#466).
The package dependencies were updated to reflect this change.
- Fixed potential DoS attack via the ``WHEEL_INFO_RE`` regular expression
- Fixed ``ValueError: ZIP does not support timestamps before 1980`` when using
``SOURCE_DATE_EPOCH=0`` or when on-disk timestamps are earlier than 1980-01-01. Such
timestamps are now changed to the minimum value before packaging.

**0.37.1 (2021-12-22)**

Expand Down
2 changes: 2 additions & 0 deletions src/wheel/wheelfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@
-(?P<pyver>[^-]+?)-(?P<abi>[^-]+?)-(?P<plat>[^.]+?)\.whl$""",
re.VERBOSE,
)
MINIMUM_TIMESTAMP = 315532800 # 1980-01-01 00:00:00 UTC


def get_zipinfo_datetime(timestamp=None):
# Some applications need reproducible .whl files, but they can't do this without
# forcing the timestamp of the individual ZipInfo objects. See issue #143.
timestamp = int(os.environ.get("SOURCE_DATE_EPOCH", timestamp or time.time()))
timestamp = max(timestamp, MINIMUM_TIMESTAMP)
return time.gmtime(timestamp)[0:6]


Expand Down
16 changes: 16 additions & 0 deletions tests/test_bdist_wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,3 +202,19 @@ def test_wheelfile_line_endings(wheel_paths):
wheelfile = next(fn for fn in wf.filelist if fn.filename.endswith("WHEEL"))
wheelfile_contents = wf.read(wheelfile)
assert b"\r" not in wheelfile_contents


def test_unix_epoch_timestamps(dummy_dist, monkeypatch, tmpdir):
monkeypatch.setenv("SOURCE_DATE_EPOCH", "0")
monkeypatch.chdir(dummy_dist)
subprocess.check_call(
[
sys.executable,
"setup.py",
"bdist_wheel",
"-b",
str(tmpdir),
"--universal",
"--build-number=2",
]
)

0 comments on commit ef6b402

Please sign in to comment.