Skip to content

Commit

Permalink
common/math: fix out of bounds access in json unmarshalling (#30014)
Browse files Browse the repository at this point in the history
Co-authored-by: Martin Holst Swende <[email protected]>
  • Loading branch information
2 people authored and ucwong committed Jun 18, 2024
1 parent 608c7f9 commit 10920da
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion common/math/big.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ type HexOrDecimal256 big.Int
// It is similar to UnmarshalText, but allows parsing real decimals too, not just
// quoted decimal strings.
func (i *HexOrDecimal256) UnmarshalJSON(input []byte) error {
if len(input) > 0 && input[0] == '"' {
if len(input) > 1 && input[0] == '"' {
input = input[1 : len(input)-1]
}
return i.UnmarshalText(input)
Expand Down
2 changes: 1 addition & 1 deletion common/math/integer.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ type HexOrDecimal64 uint64
// It is similar to UnmarshalText, but allows parsing real decimals too, not just
// quoted decimal strings.
func (i *HexOrDecimal64) UnmarshalJSON(input []byte) error {
if len(input) > 0 && input[0] == '"' {
if len(input) > 1 && input[0] == '"' {
input = input[1 : len(input)-1]
}
return i.UnmarshalText(input)
Expand Down

0 comments on commit 10920da

Please sign in to comment.