Merge pull request #3186 from nspcc-dev/reduce-max-nef-size

Restrict maximum serialized NEF file size
This commit is contained in:
Roman Khimov 2023-11-20 15:19:40 +03:00 committed by GitHub
commit 7fb077e999
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 107 additions and 7 deletions

View file

@ -16,6 +16,7 @@ import (
"github.com/nspcc-dev/neo-go/pkg/smartcontract"
"github.com/nspcc-dev/neo-go/pkg/smartcontract/manifest"
"github.com/nspcc-dev/neo-go/pkg/util"
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
"github.com/stretchr/testify/require"
)
@ -84,6 +85,29 @@ func TestCompiler(t *testing.T) {
require.NoError(t, err)
},
},
{
name: "TestCompileAndSave_NEF_constraints",
function: func(t *testing.T) {
tmp := t.TempDir()
src := `package nefconstraints
var data = "%s"
func Main() string {
return data
}
`
data := make([]byte, stackitem.MaxSize-10)
for i := range data {
data[i] = byte('a')
}
in := filepath.Join(tmp, "src.go")
require.NoError(t, os.WriteFile(in, []byte(fmt.Sprintf(src, data)), os.ModePerm))
out := filepath.Join(tmp, "test.nef")
_, err := compiler.CompileAndSave(in, &compiler.Options{Outfile: out})
require.Error(t, err)
require.Contains(t, err.Error(), "serialized NEF size exceeds VM stackitem limits")
},
},
}
for _, tcase := range testCases {