fix(libc): validate output before heap alloc in to_string(float) #27926
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/27926"
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 gurtgg on 2026-11-27T20:32:16Z.
What
_ZNSt3__19to_stringEf_nid_postfix(core/libs/prx/libc/src/LibcxxToStringFloat.cpp) allocating guest heap memory before validating that the destinationresultbuffer is writable. Previously, the long-string path called_Znwm_nid_postfix(LongStringAllocationSize)beforeGuestCopyOut_nid_no_patch, mutatingGuestHeapeven whenresultwas unwritable.GuestWritable_nid_no_patch(result, sizeof(small))on the short-string path andGuestWritable_nid_no_patch(result, sizeof(LongString))before calling_Znwm_nid_postfixon the long-string path, throwing via_ZSt18_Xinvalid_argumentPKc_nid_postfiximmediately when unwritable.Tested
guest_libcxx_to_string_float(core/libs/tests/GuestLibcxxToStringFloat.cpp): addedCheckUnwritable(0.0f)andCheckUnwritable(0x1p50f)right afterApplicationHeapRegister_nid_no_patchto verifystd::invalid_argumentis thrown and checkedmalloc_stats_fast_nid_postfix(MallocManagedSize) to assertmaxSystemSize == 0 && currentSystemSize == 0(negative control failing on unmodifiedmain, where_Znwm_nid_postfixexpandsmaxSystemSize > 0), while preserving all existing float formattingCheckassertions.Checklist
main; no other open PR implements the same functionstools/check_conventions.pypasses)NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repositorymainand passes after fixSummary by CodeRabbit
to_stringnow consistently reportsstd::invalid_argumentwhen the destination is null, invalid, or not writable, for both short and long results.errno.errnoand correctly write results to valid destinations.Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-27T20:37:08Z.
Review: APPROVED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
325fee85eb:tools/check_conventions.pypassed.guest_libcxx_to_string_float_testsbuilt cleanly.guest_libcxx_to_string_float):core/libs/prx/libc/src/LibcxxToStringFloat.cppreverted tomainand the new tests kept, the suite fails: Restoring the change makes it pass again.Looks Good To Me
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-27T20:54:45Z.
Review: APPROVED
Reviewed — looks good
Nothing in the inspected changes blocks merge; output writability is checked before any guest heap allocation, and the tests cover both string representations.
What I ran
Reviewed head
325fee85eb7ead64e5203a9ef4051f80d057d4e9against the prepared diff. No build or test commands were run;repo_read.pywas used to read the prepared review files and targeted source context.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
Runtime behavior and the reported negative-control regression run were not independently verified. No repository files were excluded from the review bundle.
To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by Plyxen on 2026-11-28T05:06:02Z.
Review: APPROVED
Checked head
325fee85eb. All on Windows 11 with WinLibs GCC 15.2 (Release), applied tomaina163d4b886together with #27930, #27929, #27925, #27924, #27923, #27922, #27901, #27828, #27771, #27755, #27748, #27682, #27765.tools/check_conventions.py --headandtools/debt_fold.py --checkpassed and the full build succeeded.guest_libcxx_to_string_floatpasses, including the new unwritable-result cases. In the full CPU suite (5,120 tests) the only failures are unrelated:windows_read_trap_unknownfails onmaintoo (fixed in #28028).frame_capture_minimize,jpeg_external_toolchainandguest_pthread_mutex_contentionare timeouts under load; they pass when run on their own.guest_audio_in_capturepasses 20/20 onmainand with #27922.AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-12-01T16:37:05Z.
Review: APPROVED
Reviewed — looks good
The reviewed change prevents guest heap allocation when a long
to_string(float)result cannot be written; I found no blocking issue in the changed files.What I ran
Reviewed head
4472e6f93b737980025192d67bfcbf4b181973f5. I read both changed files, the prepared diff and metadata, and the relevantGuestCopyOutandHostWritehelper code. No tests or builds were run.Results
Negative control
The negative-control test was not run during this review; its failure on unmodified
mainis author-reported.Findings
Blocking
None.
Non-blocking
None.
Sources
Not verified
The regression test and runtime behavior on any host or console were not verified. Both files listed under
reviewedinfiles.jsonwere read; no files were excluded.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by coderabbitai[bot] on 2026-12-01T16:38:04Z.
Review: COMMENTED
🏛️ Architecture findings (1)
Advisory architecture findings (1)
💬 Code review
afce6595-da13-4bcb-8704-c1c776fbbc7cReviewing files that changed from the base of the PR and between
325fee85eband4472e6f93b.core/libs/prx/libc/src/LibcxxToStringFloat.cppcore/libs/tests/GuestLibcxxToStringFloat.cppIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 3 remain after this review.
Imported from boykopovar/AnyPS5. Originally posted by Plyxen on 2026-12-02T02:29:10Z.
Review: APPROVED
Re-checked head
4472e6f93b, merged ontomain68d65e6b14, on Windows 11 with WinLibs GCC 15.2 (Release). This fixes the armed write-watched page problem I raised.tools/check_conventions.py --headpassed, andguest_libcxx_to_string_floatpasses three times out of three.I swapped in other versions of
LibcxxToStringFloat.cppwith this head's test to see what the test catches:main's version, it fails withunwritable to_string allocated guest heap memory.325fee85eb), it fails at the same check. The long call on the shared page that the test makes read-only (GuestArenaSetProtection0x02) got pastGuestWritable, because the page stays physically writable, and allocated.HostWriterefuses that page first, so this head throws before allocating. Edited to add: that state is the test's own. The guest'smprotectcallsVirtualProtectas well, soGuestWritablewould have refused a page made read-only that way, and this is not a second bug in that version.325fee85eband only the read-only calls removed, it fails at the armed write-watched case withinvalid_argument, as I described. This head writes the page and marks it dirty.On the bot's note: opening
HostWriteonly to check marks the range as host-written even if the allocation then throws. That costs at most a needless invalidation, and the copy-out right after opens the same guard anyway.AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T08:51:50Z.
Review: COMMENTED
The full Linux
GuestLibcxxToStringFloatfixture passed against the revised head. The long-string destination preflight opens the write-watch range before probing it, and the fixture checks heap accounting and errno for the rejected output as well as the normal short- and long-string layouts.AI-assisted: yes.
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.