std.parseJson / std.parseYaml: number overflow (out_of_range.406) aborts the process

Open
#1,337 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
78/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
cpp, json, yaml
Domain
compilers

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.

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
git clone https://github.com/google/jsonnet.git
cd jsonnet && make -j$(nproc)
./jsonnet -e 'std.parseJson("1E999")'
… 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.

Dominant language
Jsonnet
Stars
7.6k
Forks
475
PR merge metrics
No merged PRs in 30d

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from google/jsonnet

All issues in google/jsonnet

Similar issues

More Compilers issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.