From f7c5ab4f438b59b451548a45d02875a6341305c4 Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Tue, 16 Aug 2022 17:19:47 +0300 Subject: [PATCH] state: check for array length in (*Contract).FromStackItem Panicing here is not appropriate. --- pkg/core/state/contract.go | 3 +++ pkg/core/state/contract_test.go | 1 + 2 files changed, 4 insertions(+) diff --git a/pkg/core/state/contract.go b/pkg/core/state/contract.go index 0b89c4b5b..26bd9bf06 100644 --- a/pkg/core/state/contract.go +++ b/pkg/core/state/contract.go @@ -61,6 +61,9 @@ func (c *Contract) FromStackItem(item stackitem.Item) error { if !ok { return errors.New("not an array") } + if len(arr) != 5 { + return errors.New("invalid structure") + } bi, ok := arr[0].Value().(*big.Int) if !ok { return errors.New("ID is not an integer") diff --git a/pkg/core/state/contract_test.go b/pkg/core/state/contract_test.go index 3f872974a..9abdd0146 100644 --- a/pkg/core/state/contract_test.go +++ b/pkg/core/state/contract_test.go @@ -98,6 +98,7 @@ func TestContractFromStackItem(t *testing.T) { item stackitem.Item }{ {"not an array", stackitem.Make(1)}, + {"wrong array", stackitem.Make([]stackitem.Item{})}, {"id is not a number", stackitem.Make([]stackitem.Item{manifItem, counter, chash, nefItem, manifItem})}, {"id is out of range", stackitem.Make([]stackitem.Item{stackitem.Make(math.MaxUint32), counter, chash, nefItem, manifItem})}, {"counter is not a number", stackitem.Make([]stackitem.Item{id, manifItem, chash, nefItem, manifItem})},