From 6002485582541df9dff3e2c782a014564e22ed07 Mon Sep 17 00:00:00 2001 From: Runxi Yu Date: Tue, 27 Jan 2026 19:05:00 +0100 Subject: hash: Use a hashAlgorithmDetails struct for single source of truth hashAlgorithm's are assumed to be valid; methods on invalid hashAlgorithms will panic from out-of-bounds read when it's not found in hashAlgorithmTable and that's expected and intended. --- pack_idx.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'pack_idx.go') diff --git a/pack_idx.go b/pack_idx.go index c4c166ef..0dbb9bcf 100644 --- a/pack_idx.go +++ b/pack_idx.go @@ -163,7 +163,7 @@ func (pi *packIndex) parse(buf []byte) error { nobj := int(readBE32(pi.fanout[len(pi.fanout)-4:])) namesStart := fanoutEnd - namesEnd := namesStart + nobj*pi.repo.hashAlgo.size() + namesEnd := namesStart + nobj*pi.repo.hashAlgo.Size() if namesEnd > len(buf) { return ErrInvalidObject } @@ -183,7 +183,7 @@ func (pi *packIndex) parse(buf []byte) error { pi.offset32 = buf[off32Start:off32End] off64Start := off32End - trailerStart := len(buf) - 2*pi.repo.hashAlgo.size() + trailerStart := len(buf) - 2*pi.repo.hashAlgo.Size() if trailerStart < off64Start { return ErrInvalidObject } @@ -253,7 +253,7 @@ func (pi *packIndex) lookup(id Hash) (packlocation, error) { lo = int(pi.fanoutEntry(first - 1)) } hi := int(pi.fanoutEntry(first)) - idx, found := bsearchHash(pi.names, pi.repo.hashAlgo.size(), lo, hi, id) + idx, found := bsearchHash(pi.names, pi.repo.hashAlgo.Size(), lo, hi, id) if !found { return packlocation{}, ErrNotFound } -- cgit v1.3.1-10-gc9f91