Skip to content

Commit 83cda2f

Browse files
Stebalienrvagg
authored andcommitted
Reject nil pointers & nil KVs
We'd previously reject the pointers in UnmarshalCBOR, but cbor-gen has moved on and will now decode null. The KVs are manually decoded and should never be nil, even now, but... I'm adding the check just to be extra safe.
1 parent 4e60a82 commit 83cda2f

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

hamt.go

+11
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,11 @@ func loadNode(
383383
}
384384

385385
for _, ch := range out.Pointers {
386+
if ch == nil {
387+
// Cannot have nil pointers.
388+
return nil, ErrMalformedHamt
389+
}
390+
386391
isLink := ch.isShard()
387392
isBucket := ch.KVs != nil
388393
if isLink == isBucket {
@@ -397,6 +402,12 @@ func loadNode(
397402
if len(ch.KVs) == 0 || len(ch.KVs) > bucketSize {
398403
return nil, ErrMalformedHamt
399404
}
405+
for _, kv := range ch.KVs {
406+
if kv == nil {
407+
// Cannot have nil pointers kvs.
408+
return nil, ErrMalformedHamt
409+
}
410+
}
400411
for i := 1; i < len(ch.KVs); i++ {
401412
if bytes.Compare(ch.KVs[i-1].Key, ch.KVs[i].Key) >= 0 {
402413
return nil, ErrMalformedHamt

0 commit comments

Comments
 (0)