Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork32k
Open
Description
Bug report
Bug description:
Background
- Relates tosupport reproducible Python builds #73894
- Reproducibility for ZipFile introduced inZipFile.writestr should respect SOURCE_DATE_EPOCH #91279
- Seehttps://reproducible-builds.org/ andhttps://reproducible-builds.org/docs/buy-in/ for why this is a good thing to have in general, andhttps://reproducible-builds.org/docs/source-date-epoch for basic information on
SOURCE_DATE_EPOCH
specifically.
Bug
If building on a reproducible environment such as NixOS, and your local timezone has a negative UTC offset, a large number of the ZipFile tests fail due to a underflow of the DOS date value:
- Zips by default store file timestamps as a DOS date and a DOS time, They are unsigned and 16-bits wide.
- NixOS sets environment variable
SOURCE_DATE_EPOCH
to315532800
(1980-01-01 00:00:00 UTC) to specifically support programs and standards assuming DOS time (stdenv: set SOURCE_DATE_EPOCH to a value python supports NixOS/nixpkgs#89794), of which zip is one. - In recent ZipFile updates,
SOURCE_DATE_EPOCH
is read from if it exists. If it exists, it's not taken as UTC and is instead converted to the system's local time:cpython/Lib/zipfile/__init__.py
Lines 625 to 628 in8d490b3
# gh-91279: Set the SOURCE_DATE_EPOCH to a specific timestamp epoch=os.environ.get('SOURCE_DATE_EPOCH') get_time=int(epoch)ifepochelsetime.time() self.date_time=time.localtime(get_time)[:6]
- If your local time has a negative UTC offset, this ends up subtracting from the minimum possible DOS date value, which underflows to what would be a negative DOS date.
- In tests,
ValueError
is raised anytime a file is written to a ZipFile, because the DOS date under reproducible systems is not in the range0 <= date <= 65535
.
CPython versions tested on:
CPython main branch
Operating systems tested on:
Linux
Linked PRs
Metadata
Metadata
Assignees
Projects
Status
No status