You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Extract() fails on integer JSON values at signed 64-bit maximum #4016
Description
Result.Extract() cannot unmarshal valid JSON integers at signed 64-bit maximum (9223372036854775807) into int / int64 fields.
This shows up in Ironic BIOS settings (nodes.ListBIOSSettings with detail=true). Vendors such as Cisco return integer schema bounds at int64 max (CoreDisableMask_, SgxEpoch, SgxLePubKeyHash*). Gophercloud then returns:
json: cannot unmarshal number 9223372036854776000 into Go struct field BIOSSetting.bios.upper_bound of type int
The original JSON contains 9223372036854775807, not 9223372036854776000. One overflowing bound fails the entire BIOS list, so clients cannot read or apply any other setting.
This is the same class of bug as #209: Request() decodes JSONResponse into any, so numbers become float64. ExtractInto() re-marshals that body and unmarshals into the typed struct. int64 max cannot be represented exactly as float64 and is rounded to 9223372036854776000, which then does not fit in int.
Changing BIOSSetting.UpperBound from *int to *int64 does not fix this. The precision is already lost before the typed field is filled.
Expected behavior
Extract() returns the BIOS settings. UpperBound is 9223372036854775807 on 64-bit (math.MaxInt).
Actual behavior
Extract() fails with the unmarshal error above. No settings are returned.
Suggested fix
Use json.Decoder.UseNumber() when decoding JSON into any in ProviderClient.Request() (and the equivalent path in pagination.PageResultFrom). UseNumber() only changes decoding into interface{}; typed structs are unchanged. json.Number re-marshals with the original digits, so Extract() can fill int / int64 fields.
A value larger than int64 would still fail Extract(). That is separate from this precision bug.
Activity