aboutsummaryrefslogtreecommitdiffstats
path: root/plumbing/format/index
diff options
context:
space:
mode:
authorAlexander Block <ablock84@gmail.com>2024-04-02 11:42:32 +0200
committerAlexander Block <ablock84@gmail.com>2024-04-06 08:30:31 +0200
commit8a3757ce0b63e842f1e466955f0a4cc2eed429eb (patch)
tree18f85251c9328a216c70b8d4b27ea150b4679a0c /plumbing/format/index
parent7bd40f548987b3f0ce544902b9c4fbdf8d310882 (diff)
downloadgo-git-8a3757ce0b63e842f1e466955f0a4cc2eed429eb.tar.gz
plumbing: Properly support skipping of non-mandatory extensions
Before this, go-git would prematurely bail out of extensions processing when an unknown extension was encountered. This had two issues: 1. It did not account for mandatory (lower case header) extensions 2. It did not properly update the calculated hash, leading to an "invalid checksum" error.
Diffstat (limited to 'plumbing/format/index')
-rw-r--r--plumbing/format/index/decoder.go38
1 files changed, 30 insertions, 8 deletions
diff --git a/plumbing/format/index/decoder.go b/plumbing/format/index/decoder.go
index 6f32418..6634688 100644
--- a/plumbing/format/index/decoder.go
+++ b/plumbing/format/index/decoder.go
@@ -24,8 +24,8 @@ var (
// ErrInvalidChecksum is returned by Decode if the SHA1 hash mismatch with
// the read content
ErrInvalidChecksum = errors.New("invalid checksum")
-
- errUnknownExtension = errors.New("unknown extension")
+ // ErrUnknownExtension is returned when an index extension is encountered that is considered mandatory
+ ErrUnknownExtension = errors.New("unknown extension")
)
const (
@@ -234,14 +234,10 @@ func (d *Decoder) readExtensions(idx *Index) error {
err = d.readExtension(idx)
if err != nil {
- break
+ return err
}
}
- if err != nil && err != errUnknownExtension {
- return err
- }
-
return d.readChecksum(expected)
}
@@ -277,7 +273,14 @@ func (d *Decoder) readExtension(idx *Index) error {
return err
}
default:
- return errUnknownExtension
+ if header[0] < 'A' || header[0] > 'Z' {
+ return ErrUnknownExtension
+ }
+
+ d := &unknownExtensionDecoder{r}
+ if err := d.Decode(); err != nil {
+ return err
+ }
}
return nil
@@ -478,3 +481,22 @@ func (d *endOfIndexEntryDecoder) Decode(e *EndOfIndexEntry) error {
_, err = io.ReadFull(d.r, e.Hash[:])
return err
}
+
+type unknownExtensionDecoder struct {
+ r *bufio.Reader
+}
+
+func (d *unknownExtensionDecoder) Decode() error {
+ var buf [1024]byte
+
+ for {
+ _, err := d.r.Read(buf[:])
+ if err == io.EOF {
+ break
+ }
+ if err != nil {
+ return err
+ }
+ }
+ return nil
+}