Skip to content

fix(json2): accept a number that underflows to zero on libc++ - #12261

Merged
oneandonlydean merged 1 commit into
boykopovar:mainfrom
tkcm01:fix/json2-underflow-libcxx
Oct 28, 2026
Merged

oneandonlydean merged 1 commit into
boykopovar:mainfrom
tkcm01:fix/json2-underflow-libcxx

Conversation

@tkcm01

@tkcm01 tkcm01 commented Oct 28, 2026

Copy link
Copy Markdown
Contributor

What

libSceJson2's number parser falls back to an istringstream when std::from_chars reports result_out_of_range, and it accepts the value only if the stream didn't fail (Export.cpp). With libstdc++, the stream sets failbit only on overflow, so a number that underflows to zero, such as 2.4703282292062327e-324, is read as 0 and accepted. libc++ sets failbit on any ERANGE but still stores the value (±0, or ±inf on overflow). So on macOS the parse throws number 2.4703282292062327e-324 overflows a double, and guest_json_numeric_locale aborts. A failed read whose value is 0 is now accepted. On libstdc++ nothing changes: underflow sets no failbit there, and overflow gives ±DBL_MAX. On libc++, overflow still gives inf and still throws, and 1e309 still throws as the test requires.

The text reaching this line has already passed the parser's number grammar, so a 0 here can only come from underflow. #10378 replaces this block with its own decimal parser; the two would conflict, but this is a one-line fix. Announced on #1.

Tested

macOS 27.0.1 (26A434), Apple M4, Apple clang 21.0.0 (libc++), x86-64 Release build under Rosetta 2. The libraries don't link on macOS from main alone, so the tree is main 9fc181dde5 plus the open PRs @imellag listed on #1 (#7631, #7804, #10552, #11249, #11447, #10669, #11554) and #12076. Export.cpp and the test are the same there as on main.

  • ctest -R '^guest_json_numeric_locale$' -V:
    • Without this change: aborts 3 of 3 with the uncaught sce::Json::Parser::parse: number 2.4703282292062327e-324 overflows a double; the console's behaviour is unverified.
    • With it: passes 5 of 5 (--repeat until-fail:5).
  • Full ctest -j4 --timeout 120 with Vulkan: 2584 tests. Without the change, 61 failed. With it, 59 failed, with no new failures. guest_json_numeric_locale now passes, and precise_wait, a known flake here, passed in that run.
  • Windows, through the fork's Build workflow on this change merged with main: the 482 selected tests passed, guest_json_numeric_locale among them.
  • python3 tools/check_conventions.py --base upstream/main: passed. tools/pr_overlap.py: feat(libSceJson2): implement allocator-backed values and recovery #10378 (Export.cpp L460-471).

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes

🤖 Generated with Claude Code

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@tkcm01 tkcm01 mentioned this pull request Oct 28, 2026
@github-actions

Copy link
Copy Markdown

Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.

Pull request Conflicting files (lines on main) Same exports Same new files
PR 10378 core/libs/prx/libSceJson2/Export.cpp L460-471

@github-actions github-actions Bot added the prx label Oct 28, 2026

@MarcZX10 MarcZX10 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.

The change is narrowly limited to the libc++ fallback: it accepts a failed stream conversion only when the parsed value is zero, covering underflow while retaining the non-finite overflow rejection. The regression reproduces on macOS and passes repeatedly with the change; Windows CI also passes. The commit-charge/root checks and conventions pass. No blocking issue found.

@oneandonlydean oneandonlydean self-assigned this Oct 28, 2026
@oneandonlydean
oneandonlydean merged commit 6ddb12d into boykopovar:main Oct 28, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants