From b937525a24f604919e255f2980467869e1efec45 Mon Sep 17 00:00:00 2001 From: Martin Holst Swende Date: Wed, 27 Oct 2021 13:28:50 +0200 Subject: [PATCH] cmd/evm: handle rlp errors in t9n (#23771) * cmd/evm: handle rlp errors in t9n * cmd/evm/testdata: fix readme --- cmd/evm/internal/t8ntool/transaction.go | 3 +++ cmd/evm/t8n_test.go | 9 +++++++++ cmd/evm/testdata/18/README.md | 9 +++++++++ cmd/evm/testdata/18/invalid.rlp | 1 + 4 files changed, 22 insertions(+) create mode 100644 cmd/evm/testdata/18/README.md create mode 100644 cmd/evm/testdata/18/invalid.rlp diff --git a/cmd/evm/internal/t8ntool/transaction.go b/cmd/evm/internal/t8ntool/transaction.go index 29dd587d4abb..bc9bc42edc17 100644 --- a/cmd/evm/internal/t8ntool/transaction.go +++ b/cmd/evm/internal/t8ntool/transaction.go @@ -121,6 +121,9 @@ func Transaction(ctx *cli.Context) error { } var results []result for it.Next() { + if err := it.Err(); err != nil { + return NewError(ErrorIO, err) + } var tx types.Transaction err := rlp.DecodeBytes(it.Value(), &tx) if err != nil { diff --git a/cmd/evm/t8n_test.go b/cmd/evm/t8n_test.go index 4f78c5dc6d90..de6b0e5ccb6d 100644 --- a/cmd/evm/t8n_test.go +++ b/cmd/evm/t8n_test.go @@ -9,6 +9,7 @@ import ( "testing" "github.com/docker/docker/pkg/reexec" + "github.com/ethereum/go-ethereum/cmd/evm/internal/t8ntool" "github.com/ethereum/go-ethereum/internal/cmdtest" ) @@ -265,6 +266,14 @@ func TestT9n(t *testing.T) { }, expOut: "exp.json", }, + { // Invalid RLP + base: "./testdata/18", + input: t9nInput{ + inTxs: "invalid.rlp", + stFork: "London", + }, + expExitCode: t8ntool.ErrorIO, + }, } { args := []string{"t9n"} diff --git a/cmd/evm/testdata/18/README.md b/cmd/evm/testdata/18/README.md new file mode 100644 index 000000000000..360a9bba015a --- /dev/null +++ b/cmd/evm/testdata/18/README.md @@ -0,0 +1,9 @@ +# Invalid rlp + +This folder contains a sample of invalid RLP, and it's expected +that the t9n handles this properly: + +``` +$ go run . t9n --input.txs=./testdata/18/invalid.rlp --state.fork=London +ERROR(11): rlp: value size exceeds available input length +``` \ No newline at end of file diff --git a/cmd/evm/testdata/18/invalid.rlp b/cmd/evm/testdata/18/invalid.rlp new file mode 100644 index 000000000000..7ff2824caf0b --- /dev/null +++ b/cmd/evm/testdata/18/invalid.rlp @@ -0,0 +1 @@ +"0xf852328001825208870b9331677e6ebf0a801ca098ff921201554726367d2be8c804a7ff89ccf285ebc57dff8ae4c44b9c19ac4aa03887321be575c8095f789dd4c743dfe42c1820f9231f98a962b210e3ac2452a3" \ No newline at end of file