triedb/pathdb: check result

This commit is contained in:
jsvisa 2025-11-04 18:00:16 +08:00
parent 78ff9911c5
commit e71031e02f

View file

@ -387,10 +387,19 @@ func decodeSingle(keySection []byte, onValue func([]byte, int, int) error) ([]st
}
// Resolve the entry from key section
nShared, nn := binary.Uvarint(keySection[keyOff:]) // key length shared (varint)
if nn <= 0 {
return nil, fmt.Errorf("corrupted varint encoding for nShared at offset %d", keyOff)
}
keyOff += nn
nUnshared, nn := binary.Uvarint(keySection[keyOff:]) // key length not shared (varint)
if nn <= 0 {
return nil, fmt.Errorf("corrupted varint encoding for nUnshared at offset %d", keyOff)
}
keyOff += nn
nValue, nn := binary.Uvarint(keySection[keyOff:]) // value length (varint)
if nn <= 0 {
return nil, fmt.Errorf("corrupted varint encoding for nValue at offset %d", keyOff)
}
keyOff += nn
// Validate that the values can fit in an int to prevent overflow on 32-bit systems