diff options
| author | 2026-03-07 23:35:28 +0800 | |
|---|---|---|
| committer | 2026-03-07 23:35:28 +0800 | |
| commit | b279c7e4dc798b4c8055af8e974edbc8973d4537 (patch) | |
| tree | 1710e154f86d391a2f6789e37318fa6363d2beec /format/pack/ingest/trailer.go | |
| parent | internal/testgit: Add more execution helpers (diff) | |
| signature | No 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.go | 17 |
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[:]) |
