std.parseJson / std.parseYaml: number overflow (out_of_range.406) aborts the process
- Dominant language
- Jsonnet
- Stars
- 7.6k
- Forks
- 475
- PR merge metrics
- No merged PRs in 30d
Description
`std.parseJson` only catches `nlohmann::json::parse_error`. Overflowing numbers raise `out_of_range.406`, which escapes to `CATCH` in `libjsonnet.cpp` and `abort()`s. Same for `std.parseYaml("1E999")` (RapidYAML → `json::parse` without catching `out_of_range`).
Same gap as #680 / #951 (`parse_error` only). Tip `2ef32ab` / CLI v0.22.0.
### Repro
```bash
git clone https://github.com/google/jsonnet.git
cd jsonnet && make -j$(nproc)
./jsonnet -e 'std.parseJson("1E999")'
```
```text
… out_of_range.406 … number overflow parsing '1E999'
Aborted (core dumped) # exit 134
```
`./jsonnet -e 'std.parseYaml("1E999")'` → same abort.
`./jsonnet -e 'std.parseJson("{")'` → RuntimeError, no abort.
`./jsonnet -e 'std.parseJson("1e2")'` → `100`.
### Fix
Catch `json::exception` (or `out_of_range`) in `builtinParseJson` and around `json::parse` in `builtinParseYaml`; `throw makeError(...)` like #951.
Contributor guide
Research direction
Inspect libjsonnet.cpp, starting with builtinParseJson and the json::parse call used by builtinParseYaml. Run the provided build and jsonnet reproductions first; done means overflowing JSON and YAML numbers produce a Jsonnet RuntimeError rather than escaping to CATCH and aborting, while the existing parse-error behavior remains intact.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp, json, yaml
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 78/100