common/hexutil: reject big integer inputs > 256 bits

This follows the change to common/math big integer parsing in PR #3699.
This commit is contained in:
Felix Lange
2017-02-22 17:35:11 +01:00
parent c52ab932e6
commit f3b7dcc5bd
4 changed files with 30 additions and 3 deletions

View File

@ -49,6 +49,7 @@ var (
ErrOddLength = errors.New("hex string has odd length")
ErrUint64Range = errors.New("hex number does not fit into 64 bits")
ErrUintRange = fmt.Errorf("hex number does not fit into %d bits", uintBits)
ErrBig256Range = errors.New("hex number does not fit into 256 bits")
)
// Decode decodes a hex string with 0x prefix.
@ -126,11 +127,15 @@ func init() {
}
// DecodeBig decodes a hex string with 0x prefix as a quantity.
// Numbers larger than 256 bits are not accepted.
func DecodeBig(input string) (*big.Int, error) {
raw, err := checkNumber(input)
if err != nil {
return nil, err
}
if len(raw) > 64 {
return nil, ErrBig256Range
}
words := make([]big.Word, len(raw)/bigWordNibbles+1)
end := len(raw)
for i := range words {