Skip to content

Commit

Permalink
Reject nil pointers & nil KVs
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Stebalien committed Aug 2, 2024
1 parent 6caf5a5 commit 556b5df
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions hamt.go
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,11 @@ func loadNode(
}

for _, ch := range out.Pointers {
if ch == nil {
// Cannot have nil pointers.
return nil, ErrMalformedHamt
}

isLink := ch.isShard()
isBucket := ch.KVs != nil
if isLink == isBucket {
Expand All @@ -397,6 +402,12 @@ func loadNode(
if len(ch.KVs) == 0 || len(ch.KVs) > bucketSize {
return nil, ErrMalformedHamt
}
for _, kv := range ch.KVs {
if kv == nil {
// Cannot have nil pointers kvs.
return nil, ErrMalformedHamt
}
}
for i := 1; i < len(ch.KVs); i++ {
if bytes.Compare(ch.KVs[i-1].Key, ch.KVs[i].Key) >= 0 {
return nil, ErrMalformedHamt
Expand Down

0 comments on commit 556b5df

Please sign in to comment.