aboutsummaryrefslogtreecommitdiff
path: root/pack_idx.go
diff options
context:
space:
mode:
authorGravatar Runxi Yu2025-11-16 00:00:00 +0000
committerGravatar Runxi Yu2025-11-16 00:00:00 +0000
commitbd91bf5f3bcffe5d1023ab9a37e4a9425830aba9 (patch)
treee6e9fb33bfa5c455a824f0af065c54529d357c0c /pack_idx.go
parentRevert "hash: Generic hash-algorithm API" (diff)
signature
hash: Make fewer helper functions need explicit hash length fields
Diffstat (limited to 'pack_idx.go')
-rw-r--r--pack_idx.go9
1 files changed, 7 insertions, 2 deletions
diff --git a/pack_idx.go b/pack_idx.go
index 9ca28193..d313825f 100644
--- a/pack_idx.go
+++ b/pack_idx.go
@@ -3,6 +3,7 @@ package furgit
import (
"bytes"
"errors"
+ "fmt"
"os"
"path/filepath"
"strings"
@@ -243,7 +244,11 @@ func (pi *packIndex) lookup(id Hash) (packlocation, error) {
if err != nil {
return packlocation{}, err
}
- first := int(id[0])
+ // Verify hash size matches repository hash size
+ if id.size != pi.repo.HashSize {
+ return packlocation{}, fmt.Errorf("furgit: hash size mismatch: got %d, expected %d", id.size, pi.repo.HashSize)
+ }
+ first := int(id.data[0])
var lo int
if first > 0 {
lo = int(pi.fanoutEntry(first - 1))
@@ -266,7 +271,7 @@ func (pi *packIndex) lookup(id Hash) (packlocation, error) {
func bsearchHash(names []byte, stride, lo, hi int, want Hash) (int, bool) {
for lo < hi {
mid := lo + (hi-lo)/2
- cmp := compareHash(names, stride, mid, want[:stride])
+ cmp := compareHash(names, stride, mid, want.data[:stride])
if cmp == 0 {
return mid, true
}