aboutsummaryrefslogtreecommitdiff
path: root/format/pack/ingest/trailer.go
diff options
context:
space:
mode:
authorGravatar Runxi Yu2026-03-07 23:35:28 +0800
committerGravatar Runxi Yu2026-03-07 23:35:28 +0800
commitb279c7e4dc798b4c8055af8e974edbc8973d4537 (patch)
tree1710e154f86d391a2f6789e37318fa6363d2beec /format/pack/ingest/trailer.go
parentinternal/testgit: Add more execution helpers (diff)
signatureNo signature
format/pack/ingest: Use Options; don't require EOF
Diffstat (limited to 'format/pack/ingest/trailer.go')
-rw-r--r--format/pack/ingest/trailer.go17
1 files changed, 15 insertions, 2 deletions
diff --git a/format/pack/ingest/trailer.go b/format/pack/ingest/trailer.go
index ea945b10..30ba3bb8 100644
--- a/format/pack/ingest/trailer.go
+++ b/format/pack/ingest/trailer.go
@@ -8,8 +8,8 @@ import (
)
// finishAndFlushTrailer reads trailer hash bytes, verifies trailer checksum,
-// and ensures no trailing garbage remains in stream.
-func (scanner *streamScanner) finishAndFlushTrailer() error {
+// and optionally requires the source stream to hit EOF afterward.
+func (scanner *streamScanner) finishAndFlushTrailer(requireTrailingEOF bool) error {
if scanner.hashSize <= 0 {
return fmt.Errorf("format/pack/ingest: invalid hash size")
}
@@ -25,6 +25,19 @@ func (scanner *streamScanner) finishAndFlushTrailer() error {
scanner.packTrailer = append(scanner.packTrailer[:0], trailer...)
+ if scanner.n-scanner.off > 0 {
+ return fmt.Errorf("format/pack/ingest: pack has trailing garbage")
+ }
+
+ if !requireTrailingEOF {
+ computed := scanner.hash.Sum(nil)
+ if !bytes.Equal(computed, trailer) {
+ return &PackTrailerMismatchError{}
+ }
+
+ return nil
+ }
+
var probe [1]byte
n, err := scanner.Read(probe[:])