Skip to content

ZipFile tests fail in negative timezone offsets on reproducible build environments #134261

Closed

Description

@ctrlaltf2

Bug report

Bug description:

Background

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 to 315532800 (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:
    • # gh-91279: Set the SOURCE_DATE_EPOCH to a specific timestamp
      epoch = os.environ.get('SOURCE_DATE_EPOCH')
      get_time = int(epoch) if epoch else time.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 range 0 <= date <= 65535.

CPython versions tested on:

CPython main branch

Operating systems tested on:

Linux

Linked PRs

Activity

  1. added a commit that references this issue on May 19, 2025
  2. changed the title [-]Reproducibility - ZipFile tests fail in negative timezone offsets[/-] [+]Reproducibility - ZipFile tests fail in negative timezone offsets on reproducible build environments[/+] on May 19, 2025
  3. changed the title [-]Reproducibility - ZipFile tests fail in negative timezone offsets on reproducible build environments[/-] [+]ZipFile tests fail in negative timezone offsets on reproducible build environments[/+] on May 19, 2025
  4. thatch commented on May 20, 2025

    @thatch
    Contributor

    @serhiy-storchaka I agree this is an incremental improvement; I'd kind of rather we use UTC timestamps all the time but that's probably a backwards-compatibility issue.

    Related to #123059 (but there's not enough code for me to know if that's a dupe)

  5. emmatyping commented on May 27, 2025

    @emmatyping
    Member

    I think this is reasonable to change, but we should definitely document the behavior difference when we handle #123059. If you are using SOURCE_DATE_EPOCH you really want the maximally reproducible value, which is not dependent on the timezone of the local machine.

  6. emmatyping commented on May 2, 2026

    @emmatyping
    Member

    Unfortunately, the SOURCE_DATE_EPOCH code shipped in 3.14 so this is probably a behavior change we should warn users about.

  7. added 3 commits that reference this issue on May 20, 2026
  8. emmatyping commented on May 25, 2026

    @emmatyping
    Member

    I think we can close this now, as the fix is merged and backported 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    testsTests in the Lib/test dirtype-bugAn unexpected behavior, bug, or error

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions