fix: ensure we actually have a full cid

This commit is contained in:
Derrick Hammer 2024-01-24 01:51:29 -05:00
parent 7fa2e6adac
commit 9b464e0932
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 4 additions and 0 deletions

View File

@ -279,6 +279,10 @@ func initCID(bytes []byte) (*CID, error) {
return NewCID(cidType, *hash, 0), nil return NewCID(cidType, *hash, 0), nil
} }
if len(bytes) < 34 {
return nil, errors.New("invalid cid")
}
hashBytes := bytes[1:34] hashBytes := bytes[1:34]
hash := NewMultihash(hashBytes) hash := NewMultihash(hashBytes)