Skip to content

Commit c785f06

Browse files
committed
Do not assume all structs are big.Int when decoding uint128
1 parent 266071c commit c785f06

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

decoder.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,8 @@ func (d *decoder) unmarshalUint(size uint, offset uint, result reflect.Value, ui
400400
return newOffset, newUnmarshalTypeError(value, result.Type())
401401
}
402402

403+
var bigIntType = reflect.TypeOf(big.Int{})
404+
403405
func (d *decoder) unmarshalUint128(size uint, offset uint, result reflect.Value) (uint, error) {
404406
if size > 16 {
405407
return 0, newInvalidDatabaseError("the MaxMind DB file's data section contains bad data (uint128 size of %v)", size)
@@ -411,8 +413,10 @@ func (d *decoder) unmarshalUint128(size uint, offset uint, result reflect.Value)
411413

412414
switch result.Kind() {
413415
case reflect.Struct:
414-
result.Set(reflect.ValueOf(*value))
415-
return newOffset, nil
416+
if result.Type() == bigIntType {
417+
result.Set(reflect.ValueOf(*value))
418+
return newOffset, nil
419+
}
416420
case reflect.Interface:
417421
if result.NumMethod() == 0 {
418422
result.Set(reflect.ValueOf(value))

0 commit comments

Comments
 (0)