#38277 [BC-Insight] Potential Out-of-Range Panic in `UnmarshalJSON()` of `HexOrDecimal256`
Previous#37300 [BC-Insight] Incorrect Encoding of Negative *big.Int Values in MakeTopicsNext#37583 [SC-Low] Incorrect For Annotation Parsing
Was this helpful?
Was this helpful?
Was this helpful?
func (i *HexOrDecimal256) UnmarshalJSON(input []byte) error {
if len(input) > 0 && input[0] == '"' {
input = input[1 : len(input)-1]
}
return i.UnmarshalText(input)
}type EphemeralExecResult struct {
StateRoot libcommon.Hash `json:"stateRoot"`
TxRoot libcommon.Hash `json:"txRoot"`
ReceiptRoot libcommon.Hash `json:"receiptsRoot"`
LogsHash libcommon.Hash `json:"logsHash"`
Bloom types.Bloom `json:"logsBloom" gencodec:"required"`
Receipts types.Receipts `json:"receipts"`
Rejected RejectedTxs `json:"rejected,omitempty"`
Difficulty *math.HexOrDecimal256 `json:"currentDifficulty" gencodec:"required"`
GasUsed math.HexOrDecimal64 `json:"gasUsed"`
StateSyncReceipt *types.Receipt `json:"-"`
}package math
import (
"bytes"
"encoding/hex"
"math/big"
"testing"
"github.com/erigontech/erigon-lib/common"
)
func TestHexOrDecimal256UnmarshalJSON(t *testing.T) {
input := []byte{'"'}
var num HexOrDecimal256
_ = num.UnmarshalJSON(input)
}=== RUN TestHexOrDecimal256UnmarshalJSON
--- FAIL: TestHexOrDecimal256UnmarshalJSON (0.00s)
panic: runtime error: slice bounds out of range [1:0] [recovered]
panic: runtime error: slice bounds out of range [1:0]
goroutine 21 [running]:
testing.tRunner.func1.2({0x5a8b880, 0xc0000b8198})
/Users/***/go/pkg/mod/golang.org/[email protected]/src/testing/testing.go:1632 +0x230
testing.tRunner.func1()
/Users/***/go/pkg/mod/golang.org/[email protected]/src/testing/testing.go:1635 +0x35e
panic({0x5a8b880?, 0xc0000b8198?})
/Users/***/go/pkg/mod/golang.org/[email protected]/src/runtime/panic.go:785 +0x132
github.com/erigontech/erigon-lib/common/math.(*HexOrDecimal256).UnmarshalJSON(0xc000055f50?, {0xc00009ab28?, 0x151219ae47ae7?, 0x2a697f88?})
/Users/***/immunefi/erigon/erigon-lib/common/math/big.go:63 +0x48
github.com/erigontech/erigon-lib/common/math.TestHexOrDecimal256UnmarshalJSON(0xc0000bc9c0?)
/Users/***/immunefi/erigon/erigon-lib/common/math/big_test.go:34 +0x46
testing.tRunner(0xc0000bc9c0, 0x5aa1418)
/Users/***/go/pkg/mod/golang.org/[email protected]/src/testing/testing.go:1690 +0xf4
created by testing.(*T).Run in goroutine 1
/Users/***/go/pkg/mod/golang.org/[email protected]/src/testing/testing.go:1743 +0x390
Process finished with the exit code 1