Skip to content

Preserve integer precision when decoding JSON into any - #4017

Merged
mandre merged 1 commit into
gophercloud:mainfrom
elfosardo:fix-json-number-extract
Sep 17, 2026
Merged

mandre merged 1 commit into
gophercloud:mainfrom
elfosardo:fix-json-number-extract

Conversation

@elfosardo

Copy link
Copy Markdown
Contributor

Extract() round-trips Result.Body through json.Marshal. Decoding into any as float64 rounds signed 64-bit maximum values, so BIOS upper_bound 9223372036854775807 fails unmarshal into int. Use json.Decoder.UseNumber() so those integers survive Extract().

Fixes #4016

@github-actions github-actions Bot added edit:baremetal This PR updates baremetal code edit:gophercloud This PR updates common Gophercloud code semver:patch No API change backport-v2 This PR will be backported to v2 labels Sep 16, 2026
@elfosardo
elfosardo force-pushed the fix-json-number-extract branch from 9ba32b1 to 55e7080 Compare September 16, 2026 15:56
@github-actions github-actions Bot added the edit:networking This PR updates networking code label Sep 16, 2026
@coveralls

coveralls commented Sep 16, 2026 •

Copy link
Copy Markdown

Coverage Status

coverage: 63.593% (-0.02%) from 63.61% — elfosardo:fix-json-number-extract into gophercloud:main

@mandre mandre left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. I believe there are more places where we need to decode json using UseNumber().

We may want to directly fix ExtractInto() but that wouldn't be great because it's would change the any-typed field behavior for all callers.

Instead, we should inline the call to ExtractInto() from extractIntoPtr(), using UseNumber():

gophercloud/results.go

Lines 75 to 79 in d575108

var m map[string]any
err := r.ExtractInto(&m)
if err != nil {
return err
}

It should become:

var m map[string]any
b, err := json.Marshal(r.Body)
if err != nil {
 	return err
}
dec := json.NewDecoder(bytes.NewReader(b))
dec.UseNumber()
err = dec.Decode(&m)return err
}

Extract() round-trips Result.Body through json.Marshal. Decoding into
any as float64 rounds signed 64-bit maximum values, so BIOS
upper_bound 9223372036854775807 fails unmarshal into int. Use
json.Decoder.UseNumber() so those integers survive Extract().
@elfosardo
elfosardo force-pushed the fix-json-number-extract branch from 55e7080 to 97b1e61 Compare September 17, 2026 08:42
@elfosardo
elfosardo requested a review from mandre September 17, 2026 08:43
@mandre
mandre added this pull request to the merge queue Sep 17, 2026
Merged via the queue into gophercloud:main with commit c4c9d41 Sep 17, 2026
73 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport-v2 This PR will be backported to v2 edit:baremetal This PR updates baremetal code edit:gophercloud This PR updates common Gophercloud code edit:networking This PR updates networking code semver:patch No API change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Extract() fails on integer JSON values at signed 64-bit maximum

3 participants