btcjson: check if both begin and end are numbers in UnmarshalJSON

This commit is contained in:
Bruno Garcia 2024-08-23 16:22:54 -03:00 committed by GitHub
parent 029e5a3cb5
commit 1a1dd2a2b3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -903,9 +903,14 @@ func (r *DescriptorRange) UnmarshalJSON(data []byte) error {
if len(v) != 2 {
return fmt.Errorf("expected [begin,end] integer range, got: %v", unmarshalled)
}
begin, ok1 := v[0].(float64)
end, ok2 := v[1].(float64)
if !ok1 || !ok2 {
return fmt.Errorf("expected both begin and end to be numbers, got: %v", v)
}
r.Value = []int{
int(v[0].(float64)),
int(v[1].(float64)),
int(begin),
int(end),
}
default:
return fmt.Errorf("invalid descriptor range value: %v", unmarshalled)