Skip to content

Commit

Permalink
container: check id length in the getContainerSize, fix #321
Browse files Browse the repository at this point in the history
Unfortunately, we can't check for more. Epoch number is serialized in a way
that is dynamic in size.

Signed-off-by: Roman Khimov <roman@nspcc.ru>
  • Loading branch information
roman-khimov committed Mar 22, 2023
1 parent 6448e23 commit 65a8999
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
5 changes: 5 additions & 0 deletions container/container_contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -559,6 +559,11 @@ func PutContainerSize(epoch int, cid []byte, usedSize int, pubKey interop.Public
func GetContainerSize(id []byte) containerSizes {
ctx := storage.GetReadOnlyContext()

if len(id) < len(estimateKeyPrefix)+containerIDSize ||
string(id[:len(estimateKeyPrefix)]) != estimateKeyPrefix {
panic("wrong estimation prefix")
}

// V2 format
// this `id` expected to be from `ListContainerSizes`
// therefore it is not contains postfix, we ignore it in the cut.
Expand Down
4 changes: 4 additions & 0 deletions tests/container_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,10 @@ func TestContainerSizeEstimation(t *testing.T) {
int64(2), cnt.id[:], int64(123), nodes[0].pub)
})

t.Run("incorrect key must fail", func(t *testing.T) {
_, err := c.TestInvoke(t, "getContainerSize", cnt.id[:])
require.Error(t, err)
})
c.WithSigners(nodes[0].signer).Invoke(t, stackitem.Null{}, "putContainerSize",
int64(2), cnt.id[:], int64(123), nodes[0].pub)
estimations := []estimation{{nodes[0].pub, 123}}
Expand Down

0 comments on commit 65a8999

Please sign in to comment.