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_midx.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'pack_midx.go') diff --git a/pack_midx.go b/pack_midx.go index 7f31e565..0c4f3213 100644 --- a/pack_midx.go +++ b/pack_midx.go @@ -1,6 +1,7 @@ package furgit import ( + "fmt" "os" "path/filepath" "strings" @@ -245,7 +246,12 @@ func (midx *multiPackIndex) lookup(id Hash) (packlocation, error) { } } - first := int(id[0]) + // Verify hash size matches repository hash size + if id.size != midx.repo.HashSize { + return packlocation{}, fmt.Errorf("furgit: hash size mismatch: got %d, expected %d", id.size, midx.repo.HashSize) + } + + first := int(id.data[0]) var lo int if first > 0 { lo = int(readBE32(midx.fanout[(first-1)*4 : first*4])) -- cgit v1.3.1-10-gc9f91