fix(libSceJson2): saturate the decimal exponent instead of wrapping it #16207
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/16207"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-05T20:44:58Z.
What
sce::Json::Parserdecimal conversion (ParseDecimalincore/libs/prx/libSceJson2/Export.cpp) accumulated the exponent digits in astd::uint32_twith no overflow check. Exponents past 2^32 wrapped modulo 2^32, so1e4294967296scaled by 10^0 and parsed as 1.0 instead of overflowing. The same happened to the negative and underflow forms.fix(libSceJson2)commit): exponent digits stop accumulating once the exponent reaches 100000. The scaling loop already ends as soon as the magnitude becomes zero or infinite, which takes at most about 700 steps, so every larger exponent gives the same result as an unbounded one.test(libSceJson2)commit): new cases in the existingcore/libs/tests/GuestJsonDecimalRange.cpp(already registered asguest_json_decimal_range):1e4294967296and-1e4294967296overflow to infinity,1e-4294967296and-1e-4294967296underflow to zero of their sign,1e4294967295overflows, and a long run of leading zeros followed by4294967296overflows.docs(libSceJson2)commit):docs/dev/debt/libSceJson2.mdrecords that the exponent counter width of the reference conversion at0x7750is not measured on the console, so the console result for exponents past 2^32 and past 100000 is unverified.ParseDecimal. #12778 adds a different JSON reader test file.Tested
python3 tools/check_conventions.py --base upstream/main(all checks passed),git diff --check upstream/main(clean),python3 core/libs/tests/test_public_headers.py --audit-only(406 libraries, 30604 exports verified; no export declarations changed), andtools/pr_precheck.py(diff check, conventions, export ABI audit and test-quality heuristics passed; its build checks were not run).guest_json_decimal_rangectest. They are queued and not yet run; this section will be updated with their result.1e4294967296wraps to 0, so the parse returns 1.0 and the new cases fail; after the fix they return the infinities and zeros listed above.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by gabichuuuuu on 2026-11-10T11:12:17Z.
Review: COMMENTED
Read
33805b3c5dagainstmain.Correctness. In
ParseDecimal(core/libs/prx/libSceJson2/Export.cpp) the exponent stops accumulating once it reaches 100000 (so it never exceeds 999999 and cannot wrap). The bound is safe: the scaling loop ends whenmagnitudebecomes 0 or infinite, and from any nonzero finite double that takes well under 700 multiplications or divisions by 10, so every exponent above 100000 gives the same result an unbounded counter would. Leading zeros keep the counter at 0, so1e000...04294967296still reaches the large value.Test. The new
GuestJsonDecimalRange.cppcases fail onmain:std::uint32_t exponentwraps4294967296to 0, so1e4294967296parses as 1.0, not infinity. TheTestedsection still says the build andguest_json_decimal_rangewere not run; a Windows run of this head is reported in the PR comments, so the section should be updated with that result or one of your own.Non-blocking. The existing JSON real-number debt entry says decimal conversion follows the instructions at
0x7750and keeps the reference's results even where they differ from standard conversion. If that routine uses a 32-bit counter,main's wrap is the reference result and this change moves away from it. The new debt entry is honest that the counter width is unmeasured; reading the exponent loop at0x7750would settle which behaviour is right.Not run here; this is from reading the code.
AI-assisted: yes.