fix: avoid float overflow in mapping.Unmarshal (#3590)

This commit is contained in:
Kevin Wan
2023-09-26 21:46:34 +08:00
committed by GitHub
parent af022b9655
commit 0ee7a271d3
3 changed files with 192 additions and 13 deletions

View File

@@ -5,6 +5,7 @@ import (
"encoding/json"
"errors"
"fmt"
"math"
"reflect"
"strconv"
"strings"
@@ -614,7 +615,18 @@ func (u *Unmarshaler) processFieldPrimitiveWithJSONNumber(fieldType reflect.Type
if err := setValueFromString(typeKind, target, v.String()); err != nil {
return err
}
case reflect.Float32, reflect.Float64:
case reflect.Float32:
fValue, err := v.Float64()
if err != nil {
return err
}
if fValue > math.MaxFloat32 {
return float32OverflowError(v.String())
}
target.SetFloat(fValue)
case reflect.Float64:
fValue, err := v.Float64()
if err != nil {
return err