Commit 983a9b0
authored
Fix int64 precision loss in JSON loader (#5494)
## Why
Found during a full-repo review of the CLI. The JSON loader decodes
every number as float64, which has a 53-bit mantissa. Integer values
above 2^53 silently lose precision, and job, run, and pipeline IDs
routinely exceed that. For example, `--json '{"job_id":
123456789012345678}'` unmarshals to `123456789012345680` and targets the
wrong resource. The corruption happens at load time, so the precision
guard in `convert.Normalize` never sees the original value.
## Changes
Before, all JSON numbers became float64; now integer literals are loaded
as int64 and keep their exact value. The loader in
`libs/dyn/jsonloader/json.go` enables `decoder.UseNumber()` and handles
the `json.Number` token: integer literals parse as int64, while literals
with a fraction or exponent (`2.0`, `1e3`) stay float64. Integer
literals that overflow int64 also fall back to float64, matching the
previous decoder behavior.
This affects everything loading through `jsonloader`: the `--json` flag
on generated commands and bundle variable files. Both paths normalize
values against the target type afterwards, and `convert.Normalize`
already converts int to float (and back) with precision checks, so
well-formed inputs are unaffected apart from no longer being corrupted.
## Test plan
- [x] New unit tests in `libs/dyn/jsonloader`: large positive and
negative int64 values, max int64, floats with fraction or exponent,
int64 overflow fallback, out-of-range error, and a mixed object
converted via `convert.ToTyped` asserting the exact job ID
- [x] `go test ./libs/dyn/...`
- [x] `go test ./libs/flags ./bundle/config/mutator` (the two `LoadJSON`
consumers)
- [x] Acceptance tests covering JSON inputs pass unchanged:
`bundle/variables/file-defaults`, `cmd/workspace/apps`,
`cmd/workspace/database/update-database-instance`
- [x] `./task fmt-q`, `./task lint-q`, `./task checks`
This pull request and its description were written by Isaac.1 parent 58c0974 commit 983a9b0
2 files changed
Lines changed: 61 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
20 | 23 | | |
21 | 24 | | |
22 | 25 | | |
| |||
107 | 110 | | |
108 | 111 | | |
109 | 112 | | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
110 | 123 | | |
111 | 124 | | |
112 | 125 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| 9 | + | |
9 | 10 | | |
10 | 11 | | |
11 | 12 | | |
| |||
111 | 112 | | |
112 | 113 | | |
113 | 114 | | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
0 commit comments