From bd91bf5f3bcffe5d1023ab9a37e4a9425830aba9 Mon Sep 17 00:00:00 2001 From: Runxi Yu Date: Sun, 16 Nov 2025 00:00:00 +0000 Subject: hash: Make fewer helper functions need explicit hash length fields --- pack_idx.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'pack_idx.go') 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 } -- cgit v1.3.1-10-gc9f91