Repository navigation
alpine: hash only the bytes read when computing the control.tar.gz digest - #2908
Merged
Merged
Conversation
…gest sha1Reader.Read hashed the whole buffer p instead of p[:n], so when the underlying reader returns a short read the stale tail of p is folded into the control.tar.gz SHA1 that the package signature is verified against, making a validly signed package fail verification. Added TestAlpinePackagePartialReads, which unmarshals the existing signed fixture through a reader that returns one byte per call and checks the digest matches the whole-file read and the signature still verifies. Signed-off-by: sueun-dev <sueun.dev@gmail.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2908 +/- ##
===========================================
- Coverage 66.46% 27.69% -38.77%
===========================================
Files 92 192 +100
Lines 9258 20344 +11086
===========================================
- Hits 6153 5635 -518
- Misses 2359 13842 +11483
- Partials 746 867 +121
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
bobcallaway
approved these changes
Aug 3, 2026
stgrace
pushed a commit
to stgrace/rekor
that referenced
this pull request
Aug 22, 2026
…gest (sigstore#2908) sha1Reader.Read hashed the whole buffer p instead of p[:n], so when the underlying reader returns a short read the stale tail of p is folded into the control.tar.gz SHA1 that the package signature is verified against, making a validly signed package fail verification. Added TestAlpinePackagePartialReads, which unmarshals the existing signed fixture through a reader that returns one byte per call and checks the digest matches the whole-file read and the signature still verifies. Signed-off-by: sueun-dev <sueun.dev@gmail.com>
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.
sha1Reader.Readhashes the whole read buffer instead of the part that was actually filled:When the underlying read returns fewer bytes than requested (
n < len(p)), the stale tail ofpgets folded into the SHA1. That digest is the value the package signature is checked against inVerifySignature, so once it is off a validly signed package fails verification.It doesn't show up in the existing test because
Package.Unmarshalis handed an*os.File, and reads on a regular file fill the buffer. A reader that can return short reads hits it — a network stream /http.Response.Body, orbufioat a refill boundary.gzipreads the compressed stream in chunks larger than one byte, so a short read there feeds stale bytes into the digest.The fix is
Write(p[:n]).I added
TestAlpinePackagePartialReads: it unmarshals the existing signed fixture through a reader that returns one byte per call, then checks the control digest matches the whole-file read and the signature still verifies. Before the change the two digests differ and verification returnscrypto/rsa: verification error; after it, they match.