From 62ef5a8dc756df9ac411f11f0c52766fec2a6bd1 Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Mon, 8 Feb 2021 23:14:35 +0300 Subject: [PATCH] native: enforce contract manifest UTF-8 validity Refs. #1699. --- pkg/core/native/management.go | 4 ++++ pkg/core/native_management_test.go | 8 ++++++++ 2 files changed, 12 insertions(+) diff --git a/pkg/core/native/management.go b/pkg/core/native/management.go index a216fa950..e6ffcf9b2 100644 --- a/pkg/core/native/management.go +++ b/pkg/core/native/management.go @@ -7,6 +7,7 @@ import ( "math" "math/big" "sync" + "unicode/utf8" "github.com/nspcc-dev/neo-go/pkg/core/dao" "github.com/nspcc-dev/neo-go/pkg/core/interop" @@ -206,6 +207,9 @@ func (m *Management) getNefAndManifestFromItems(ic *interop.Context, args []stac resNef = &nf } if manifestBytes != nil { + if !utf8.Valid(manifestBytes) { + return nil, nil, errors.New("manifest is not UTF-8 compliant") + } resManifest = new(manifest.Manifest) err := json.Unmarshal(manifestBytes, resManifest) if err != nil { diff --git a/pkg/core/native_management_test.go b/pkg/core/native_management_test.go index 0408cac00..972a97dd9 100644 --- a/pkg/core/native_management_test.go +++ b/pkg/core/native_management_test.go @@ -1,6 +1,7 @@ package core import ( + "bytes" "encoding/json" "math/big" "testing" @@ -177,6 +178,13 @@ func TestContractDeploy(t *testing.T) { require.NoError(t, err) checkFAULTState(t, res) }) + t.Run("non-utf8 manifest", func(t *testing.T) { + manifB := bytes.Replace(manif1, []byte("TestMain"), []byte("\xff\xfe\xfd"), 1) // Replace name. + + res, err := invokeContractMethod(bc, 11_00000000, mgmtHash, "deploy", nef1b, manifB) + require.NoError(t, err) + checkFAULTState(t, res) + }) t.Run("invalid manifest", func(t *testing.T) { pkey, err := keys.NewPrivateKey() require.NoError(t, err)