fix(libc): write the numeric conversion end pointers through checked guest copies #28892
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/28892"
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 sheriffmohammed on 2026-12-04T13:38:37Z.
What
strto*,wcsto*,_Sto*and_WSto*wrote a non-nullendptrthrough the caller's pointer, so an unmapped or read-only output crashed the host. That includes the paths that store it before any digits are read: an invalid base, a bare0x/0bprefix, no conversion, and theNAN(...)sequence.Changes:
SonyStoreEndhelper inSonyCrt.hppstores the end pointer throughGuestCopyOut_nid_no_patch, keepingerrno, and throwsstd::invalid_argumentwhen the output cannot be written. This is a host-safety fallback; the console's fault behaviour is not measured.SonyStoreHostEndis a plain store, andParseIntegerHost,ParseFloatHostandParseAsciiPrefixHostonly write a host local. The checkedParseInteger,ParseFloatandParseAsciiPrefixwrappers own the guest copy at the ABI boundary, so a host-local intermediate no longer pays for aVirtualQueryon Windows._Stodx/_Stofx/_Stoldx, libc++stof/stoi/stoul/stoull, widewcstoll,_WStoll, and the_WStoullbody.strtoimax,strtoumaxand_Stoulkeep their previous invalid-baseerrnobehaviour throughsetError = false.SonyStoreEnd; results for writable pointers are unchanged.A rejected copy may have written part of the pointer, so callers must not reuse the destination after the throw; the debt entry records this. The Dinkumware
_Stod/_Stof/_Stold, their_Stodx/_Stofx/_Stoldxforms, and the versioned_Sto*functions still write the end pointer directly inScaledFloat,DecimalFloat,VersionedUnsignedandVersionedSigned; those direct stores remain out of scope.Tested
Windows 11 (10.0.26300), WinLibs GCC 15.2.0 (UCRT, POSIX, SEH), CMake 4.3.1, Ninja, Release:
GuestMath.cpp,GuestWideStrings.cppandGuestWideConversion.cppcover an unmapped (0x10) and a read-only end pointer for the narrow and wide float and integer families, theNAN(...)path, an invalid base, a binary prefix, anderrnokept across the throw.guest_math,guest_wide_stringsandguest_wide_conversionpass.guest_crt,guest_strings,guest_wide_formatting,guest_math_elementary,guest_math_exact,guest_strtod_subnormal,guest_stdio_variadic,guest_dinkumware_internals,guest_formattingandguest_localealso pass (13/13 with the three above).main, all three focused tests end in an access violation; with the fix they pass.tools/pr_overlap.py --branch fix/libc-unchecked-outputsfound no overlapping changes. #8965 conflicts withmainitself in its Annex K functions (strncpy_s,memcpy_s, ...); merging it with this branch conflicts in the same three files, so this PR adds no conflict.tools/check_conventions.pyandtools/debt_fold.py --checkpass.tools/guest_pointer_audit.py libcno longer reports anendptrfinding.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)Summary by CodeRabbit
Imported from boykopovar/AnyPS5. Originally posted by Plyxen on 2026-12-04T13:51:08Z.
Review: APPROVED
Verified on Windows 11 (GCC 15.2, Release) on main
484b0368d3. Applied together with #28891, #28890, #28817 and #27995, which touch separate files.guest_wide_strings,guest_wide_conversion,guest_math,guest_math_elementaryandguest_math_exactpassed in 3 of 3 runs.SonyCrt.hppandStrings.cppreverted to main and the tests kept,guest_wide_strings,guest_wide_conversionandguest_mathcrash on a write to0x10, the unwritable end pointer. So the tests cover each changed store.errnoatERANGEand returns the maximum on overflow. The end pointer is now stored before that return.Non-blocking: internal callers that pass a host local, like
strtod_nid_postfixpassing&parsedEndtoParseFloat, now also go throughGuestCopyOut. On Windows that costs aVirtualQueryper parse. A plain store would do for those.Not run: Linux and macOS.
AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by coderabbitai[bot] on 2026-12-04T13:51:13Z.
Review: COMMENTED
Actionable comments
fb4d4b9f-adc8-497b-a787-5d53c4fc775fReviewing files that changed from the base of the PR and between
484b0368d3and41d14ebcb2.core/libs/prx/libc/include/SonyCrt.hppcore/libs/prx/libc/src/Strings.cppcore/libs/tests/GuestMath.cppcore/libs/tests/GuestWideConversion.cppcore/libs/tests/GuestWideStrings.cppdocs/dev/debt/changes/fix-libc-unchecked-outputs.mdIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-12-04T14:35:58Z.
Review: APPROVED
Reviewed — looks good
The changed conversion end-pointer stores use checked guest copies, and I found no blocking defect in the reviewed changes.
What I ran
Reviewed head
41d14ebcb27704b9fc895a38b9e78f5c52a56c8bagainst the prepared diff and source at that pinned head usingrepo_read.py. No build or tests were run.Results
Negative control
Not run. The description reports that the three focused tests fail on unpatched
mainand pass with this change; I did not independently verify those runs.Findings
Blocking
None.
Non-blocking
None.
Sources
SonyStoreEndandParseIntegerNot verified
Linux and PS5 behavior, and the author-reported test and negative-control results, were not independently verified. I read the changed hunks and relevant context in all six reviewed files:
core/libs/prx/libc/include/SonyCrt.hpp,core/libs/prx/libc/src/Strings.cpp,core/libs/tests/GuestMath.cpp,core/libs/tests/GuestWideConversion.cpp,core/libs/tests/GuestWideStrings.cpp, anddocs/dev/debt/changes/fix-libc-unchecked-outputs.md. Untouched portions of large files were not read.files.jsonlists no excluded changed files.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by coderabbitai[bot] on 2026-12-04T15:19:12Z.
Review: COMMENTED
Actionable comments
9e3a34c3-6dbd-45f4-b54e-54a4603a4ac8Reviewing files that changed from the base of the PR and between
41d14ebcb2and3b57c95927.core/libs/prx/libc/include/General.hppcore/libs/prx/libc/include/SonyCrt.hppcore/libs/prx/libc/src/DinkumwareInternals.cppcore/libs/prx/libc/src/LibcxxSto.cppcore/libs/prx/libc/src/RuntimeSupport.cppcore/libs/prx/libc/src/Strings.cppdocs/dev/debt/changes/fix-libc-unchecked-outputs.mdIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-12-04T15:52:38Z.
Review: APPROVED
Reviewed — looks good
The reviewed change is at head
d56ec94b15bc76d277a6c22d1a9abf1417e48747; the checked-copy wrappers and host-local parser paths are consistent in the inspected code, with no verified blocking findings.What I ran
Read
diff.patch,manifest.json,description.md, andcommits.md, then usedrepo_read.pyat the pinned head to inspect the changed parser code and relevant callers. No tests, builds, or negative controls were run.Results
Negative control
Not run by this reviewer. The PR description reports that the three focused tests access-violate on unpatched
mainand pass with this change; that report was not independently verified.Findings
Blocking
None.
Non-blocking
None.
Sources
Not verified
No tests or builds were run, and Windows test results in the description were not independently checked. Linux and PS5 behavior, including console fault behavior, was not verified. All ten changed files listed in
manifest.jsonwere reviewed indiff.patch; targeted head context was read forGeneral.hpp,SonyCrt.hpp,DinkumwareInternals.cpp,LibcxxSto.cpp,RuntimeSupport.cpp, andStrings.cpp.GuestMath.cpp,GuestWideConversion.cpp,GuestWideStrings.cpp, and the debt entry were reviewed from the prepared diff and included file text. No files were excluded by the supplied review manifest.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by Plyxen on 2026-12-04T16:05:12Z.
Review: APPROVED
Re-verified head
d56ec94b15on Windows 11 (GCC 15.2, Release), applied alone to main484b0368d3.guest_wide_strings,guest_wide_conversion,guest_math,guest_math_elementary,guest_math_exact,guest_strtod_subnormal,guest_wide_stream_scan,guest_dinkumware_internals,guest_dinkumware_float_bitsandguest_libcxx_sto: 10 of 10 pass, as on main.guest_wide_strings,guest_wide_conversionandguest_mathcrash on the write to0x10, the unwritable end pointer. The other 7 still pass.This head also resolves my earlier non-blocking note: host-side callers (
_Stodx, thesto*family,strtoimaxand_StoulthroughParseIntegerHost, and the ASCII prefix parsers) now go through the*Hosthelpers with a plain store. Only the guest-facing end pointer goes throughGuestCopyOut.Not run: Linux and macOS.
AI-assisted: yes (Claude Code)
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.