native: enforce contract manifest UTF-8 validity

Refs. #1699.
This commit is contained in:
Roman Khimov 2021-02-08 23:14:35 +03:00
parent dc3967ae7b
commit 62ef5a8dc7
2 changed files with 12 additions and 0 deletions

View file

@ -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 {

View file

@ -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)