From 3456d9222042c547c580eecfa470c17888fdd30d Mon Sep 17 00:00:00 2001 From: Furetur Date: Wed, 3 Jul 2024 12:48:00 +0300 Subject: [PATCH] mptdata: add test for MaxArraySize This commit adds a single test that covers the previously uncovered branch in the mptdata decoding algorithm. Signed-off-by: Furetur --- pkg/network/payload/mptdata_test.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/pkg/network/payload/mptdata_test.go b/pkg/network/payload/mptdata_test.go index d9db7bff6..4c02cce15 100644 --- a/pkg/network/payload/mptdata_test.go +++ b/pkg/network/payload/mptdata_test.go @@ -21,4 +21,18 @@ func TestMPTData_EncodeDecodeBinary(t *testing.T) { } testserdes.EncodeDecodeBinary(t, d, new(MPTData)) }) + + t.Run("exceeds MaxArraySize", func(t *testing.T) { + bytes := []byte{ + // The first byte represents the number 0x1. + // It encodes the size of the outer array (the number or rows in the Nodes matrix). + 0x1, + // This sequence of 9 bytes represents the number 0xffffffffffffffff. + // It encodes the size of the first row in the Nodes matrix. + // This size exceeds the maximum array size, thus the decoder should + // return an error. + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + } + require.Error(t, testserdes.DecodeBinary(bytes, new(MPTData))) + }) }