Repository navigation
pkg/epoch: reject negative SOURCE_DATE_EPOCH values - #13817
Merged
samuelkarp merged 1 commit intoJul 25, 2026
Merged
samuelkarp merged 1 commit into
samuelkarp merged 1 commit into
Conversation
Contributor
There was a problem hiding this comment.
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_EPOCHvalues inParseSourceDateEpochwith a clear error. - Add a regression test to ensure negative values fail both
SourceDateEpoch()(env var path) andParseSourceDateEpoch()(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
marked this pull request as ready for review
July 22, 2026 21:46
nikolauspschuetz
force-pushed
the
test-epoch-reject-negative-source-date-epoch
branch
from
July 22, 2026 21:46
8e1d793 to
41f6f0e
Compare
AkihiroSuda
approved these changes
Jul 25, 2026
samuelkarp
approved these changes
Jul 25, 2026
samuelkarp
enabled auto-merge
July 25, 2026 20:38
This was referenced Sep 15, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
ParseSourceDateEpochusesstrconv.ParseInt, which accepts a leading sign, so a negativeSOURCE_DATE_EPOCH(e.g.-1) is silently accepted and returns a pre-1970 timestamp with anilerror. That contradicts both the function's own godoc ("returns an error if ... not well-formatted") and the reproducible-builds spec, whereSOURCE_DATE_EPOCHis a non-negative number of seconds since the Unix epoch.This rejects negative values with an error and adds a regression test. The existing
WithInvalidSourceDateEpochcase only covered a non-numeric string ("foo"), so the negative case was untested.