Skip to content

Commit da6cf0f

Browse files
Fix insufficient array length validation (#474)
1 parent c07e385 commit da6cf0f

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

pkg/ccip/bindings/common/common.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ import (
1414
"github.com/xssnick/tonutils-go/tvm/cell"
1515
)
1616

17+
// MaxArrayLength defines the maximum length for arrays packed with reference chaining to prevent excessive resource consumption.
18+
const MaxArrayLength = 1000
19+
1720
//go:generate go run golang.org/x/tools/cmd/[email protected] -type=ExitCode
1821
type ExitCode tvm.ExitCode
1922

@@ -219,10 +222,16 @@ func unpackArrayWithRefChaining[T any](root *cell.Cell) ([]T, error) {
219222
for curr != nil {
220223
length := curr.RefsNum()
221224

222-
// sanity check for length
225+
// defensive sanity check for length, in real scenarios this should never happen since cell refs are limited to 4
223226
if length > uint(math.MaxInt) {
224227
return result, fmt.Errorf("length %d overflows int", length)
225228
}
229+
230+
// same defensive sanity check for length, in real scenarios this should never happen
231+
if length > MaxArrayLength {
232+
return nil, fmt.Errorf("array length %d exceeds maximum of %d", length, MaxArrayLength)
233+
}
234+
226235
for i := 0; i < int(length); i++ {
227236
ref, err := curr.PeekRef(i)
228237
if err != nil {

0 commit comments

Comments
 (0)