fix(libc): safely probe the guest memory of mbrtoc32 and mbrtoc16 #20600
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/20600"
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 milescoviello on 2026-11-15T10:50:14Z.
What
mbrtoc32andmbrtoc16read and wrote the conversion state, read the source bytes and stored the decoded character or code unit straight through the guest pointers. A non-null pointer to unmapped memory faulted the host.The state's 12 bytes (the 8-byte partial value and the pending count at offset 10) are now copied into a local with
GuestCopyIn_nid_no_patchand copied back withGuestCopyOut_nid_no_patchwherever the state was stored before. The source is read one byte at a time the same way, and the result is written withGuestCopyOut_nid_no_patch.(size_t)-1witherrnoEFAULT(14), the way the othererrno-reporting libc paths fail on bad memory, and leaves the state as it was.std::invalid_argumentboth functions already throw for a null state, since the state is required.The decoding, the return values, the
EILSEQpaths, the pending low surrogate ofmbrtoc16and the null-source and null-destination behaviour are unchanged.General.hppis included at the same place #18112 and #13730 include it, so either merges cleanly with this branch (checked withgit merge-tree). The debt entry goes in a fragment underdocs/dev/debt/changes/and records this as unmeasured.Tested
Linux (Ubuntu 26.04.1), GCC 15.2, Release.
guest_wide_strings, for both functions:0x10) or an unmapped source returns(size_t)-1witherrno14, and an unmapped state throws;€leaves the pending count at 1, and the retry with a valid destination completes it;mbrtoc16, an unmapped destination for the high surrogate of U+1F600 leaves the state empty, and an unmapped destination for the pending low surrogate leaves it pending (0x10); the retry returns -3 with0xdc00.The existing
mbrtoc32/mbrtoc16cases (UTF-8 lengths, split sequences, null source,EILSEQ, surrogate pairs) and the rest of the file still pass.Negative control: with
Multibyte.cppfrommainand these tests,guest_wide_stringssegfaults.git merge-treeagainst the heads of the open PRs that touchMultibyte.cpporGuestWideStrings.cpp(#18112, #13730, #20395, #19720, #19670, #19645, #19635, #19628, #19562, #16308): no conflicts.tools/check_conventions.pypasses on the branch and this body;tools/debt_fold.py --checkpasses with the fragment applied tomain.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)Pull request closed