aboutsummaryrefslogtreecommitdiff
path: root/objectstore
diff options
context:
space:
mode:
Diffstat (limited to 'objectstore')
-rw-r--r--objectstore/packed/pack_idx_checksum.go30
-rw-r--r--objectstore/packed/store.go3
2 files changed, 31 insertions, 2 deletions
diff --git a/objectstore/packed/pack_idx_checksum.go b/objectstore/packed/pack_idx_checksum.go
new file mode 100644
index 00000000..2f55a469
--- /dev/null
+++ b/objectstore/packed/pack_idx_checksum.go
@@ -0,0 +1,30 @@
+package packed
+
+import (
+ "bytes"
+ "fmt"
+
+ "codeberg.org/lindenii/furgit/objectid"
+)
+
+// verifyMappedPackMatchesMappedIdx compares one mapped pack trailer hash with
+// the pack hash recorded in one mapped idx trailer.
+func verifyMappedPackMatchesMappedIdx(packData, idxData []byte, algo objectid.Algorithm) error {
+ hashSize := algo.Size()
+ if hashSize <= 0 {
+ return objectid.ErrInvalidAlgorithm
+ }
+ if len(packData) < hashSize {
+ return fmt.Errorf("objectstore/packed: pack too short for trailer hash")
+ }
+ if len(idxData) < hashSize*2 {
+ return fmt.Errorf("objectstore/packed: idx too short for trailer hashes")
+ }
+
+ packTrailerHash := packData[len(packData)-hashSize:]
+ idxPackHash := idxData[len(idxData)-hashSize*2 : len(idxData)-hashSize]
+ if !bytes.Equal(packTrailerHash, idxPackHash) {
+ return fmt.Errorf("objectstore/packed: pack hash does not match idx")
+ }
+ return nil
+}
diff --git a/objectstore/packed/store.go b/objectstore/packed/store.go
index bb6936ea..abd7175f 100644
--- a/objectstore/packed/store.go
+++ b/objectstore/packed/store.go
@@ -7,7 +7,6 @@ import (
"os"
"sync"
- packchecksum "codeberg.org/lindenii/furgit/format/pack/checksum"
"codeberg.org/lindenii/furgit/objectid"
"codeberg.org/lindenii/furgit/objectstore"
)
@@ -195,7 +194,7 @@ func (store *Store) verifyPackMatchesIndexes(pack *packFile) error {
if err != nil {
return err
}
- if err := packchecksum.VerifyPackMatchesIdx(pack.data, index.data, store.algo); err != nil {
+ if err := verifyMappedPackMatchesMappedIdx(pack.data, index.data, store.algo); err != nil {
return fmt.Errorf("objectstore/packed: pack %q does not match idx %q: %w", pack.name, index.idxName, err)
}
return nil