@@ -185,11 +185,13 @@ func (p *Packfile) find(offset int64) (Chain, error) {
185185func (p * Packfile ) findBase (typ PackedObjectType , offset , objOffset int64 ) (Chain , int64 , error ) {
186186 var baseOffset int64
187187
188- // We assume that we have to read at least 20 bytes (the SHA-1 length in
189- // the case of a OBJ_REF_DELTA, or greater than the length of the base
190- // offset encoded in an OBJ_OFS_DELTA).
191- var sha [20 ]byte
192- if _ , err := p .r .ReadAt (sha [:], offset ); err != nil {
188+ hashlen := p .hash .Size ()
189+
190+ // We assume that we have to read at least an object ID's worth (the
191+ // hash length in the case of a OBJ_REF_DELTA, or greater than the
192+ // length of the base offset encoded in an OBJ_OFS_DELTA).
193+ var sha [32 ]byte
194+ if _ , err := p .r .ReadAt (sha [:hashlen ], offset ); err != nil {
193195 return nil , baseOffset , err
194196 }
195197
@@ -217,13 +219,13 @@ func (p *Packfile) findBase(typ PackedObjectType, offset, objOffset int64) (Chai
217219 // If the delta is an OBJ_REFS_DELTA, find the location of its
218220 // base by reading the SHA-1 name and looking it up in the
219221 // corresponding pack index file.
220- e , err := p .idx .Entry (sha [:])
222+ e , err := p .idx .Entry (sha [:hashlen ])
221223 if err != nil {
222224 return nil , baseOffset , err
223225 }
224226
225227 baseOffset = int64 (e .PackOffset )
226- offset += 20
228+ offset += int64 ( hashlen )
227229 default :
228230 // If we did not receive an OBJ_OFS_DELTA, or OBJ_REF_DELTA, the
229231 // type given is not a delta-fied type. Return an error.
0 commit comments