Skip to content

pkg/epoch: reject negative SOURCE_DATE_EPOCH values - #13817

Merged
samuelkarp merged 1 commit into
containerd:mainfrom
nikolauspschuetz:test-epoch-reject-negative-source-date-epoch
Jul 25, 2026
Merged

samuelkarp merged 1 commit into
containerd:mainfrom
nikolauspschuetz:test-epoch-reject-negative-source-date-epoch

Conversation

@nikolauspschuetz

Copy link
Copy Markdown
Contributor

ParseSourceDateEpoch uses strconv.ParseInt, which accepts a leading sign, so a negative SOURCE_DATE_EPOCH (e.g. -1) is silently accepted and returns a pre-1970 timestamp with a nil error. That contradicts both the function's own godoc ("returns an error if ... not well-formatted") and the reproducible-builds spec, where SOURCE_DATE_EPOCH is a non-negative number of seconds since the Unix epoch.

This rejects negative values with an error and adds a regression test. The existing WithInvalidSourceDateEpoch case only covered a non-numeric string ("foo"), so the negative case was untested.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR tightens pkg/epoch’s handling of SOURCE_DATE_EPOCH by rejecting negative values, aligning behavior with the reproducible-builds specification and the function’s “well-formatted” contract.

Changes:

  • Reject negative SOURCE_DATE_EPOCH values in ParseSourceDateEpoch with a clear error.
  • Add a regression test to ensure negative values fail both SourceDateEpoch() (env var path) and ParseSourceDateEpoch() (direct parse path).

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
pkg/epoch/epoch.go Add non-negative validation after parsing SOURCE_DATE_EPOCH.
pkg/epoch/epoch_test.go Add test coverage for negative SOURCE_DATE_EPOCH inputs.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

ParseSourceDateEpoch used strconv.ParseInt, which accepts a leading sign, so a
negative SOURCE_DATE_EPOCH was silently accepted and produced a pre-1970
timestamp with a nil error. That contradicts the function's own doc ("returns
an error if ... not well-formatted") and the reproducible-builds spec, where
SOURCE_DATE_EPOCH is a non-negative number of seconds since the Unix epoch.
Reject negative values and add a regression test.

Signed-off-by: Nikolaus Schuetz <[email protected]>
@nikolauspschuetz
nikolauspschuetz marked this pull request as ready for review July 22, 2026 21:46
@nikolauspschuetz
nikolauspschuetz force-pushed the test-epoch-reject-negative-source-date-epoch branch from 8e1d793 to 41f6f0e Compare July 22, 2026 21:46
Copilot AI review requested due to automatic review settings July 22, 2026 21:46

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.

@AkihiroSuda AkihiroSuda added the easy-to-review Easy to review label Jul 25, 2026
@github-project-automation github-project-automation Bot moved this from Needs Triage to Review In Progress in Pull Request Review Jul 25, 2026
@samuelkarp
samuelkarp enabled auto-merge July 25, 2026 20:38
@samuelkarp
samuelkarp added this pull request to the merge queue Jul 25, 2026
Merged via the queue into containerd:main with commit f75a4ba Jul 25, 2026
88 of 90 checks passed
@github-project-automation github-project-automation Bot moved this from Review In Progress to Done in Pull Request Review Jul 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

4 participants