fix(libc): read guest wide strings as 16-bit units #1116
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1116"
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 Fishybeing on 2026-10-07T13:02:46Z.
What
The guest's
wchar_tis 16 bits (UTF-16, seeWindowsFormatting.hpp;FormattingWide.cppand_Mbtowcxalready use 16-bit units). The string functions incore/libs/prx/libc/src/Strings.cpptookwchar_t*and forwarded to the host'sstd::wcs*/std::wmem*, which only matches the guest on Windows. On Linux the host'swchar_tis 32 bits, so these read and wrote guest strings in 4-byte units:wcslenof a guest string returned a wrong length, comparisons were wrong, and the copies could overrun the guest buffer.This implements them on
char16_t:wmemchr,wmemcmp,wmemcpy,wmemmove,wmemset,wcslen,wcscmp,wcsncmp,wcscpy,wcsncpy,wcschr,wcsrchr,wcsstr,wcspbrk,wcsspnComparisons are on unsigned code units and return -1, 0 or 1, as the Windows build returned before, so Windows behaviour does not change.
The wide conversions (
wcstod,wcstof,wcstold,wcstol,wcstoll,wcstoul,wcstoull,wcscoll,wcsxfrm,wcsrtombs) andswprintfhave the same problem on Linux but need a UTF-16 conversion, so they are left for a follow-up and listed in TechnicalDebt.guest_wide_stringscovers every changed function, including code units above 0x7FFF, embedded terminators,wcsncpypadding and truncation, overlappingwmemmoveand writes past the requested count.Tested
15.2.0posix-14.0.0-ucrt-r7), Release,-DBUILD_TESTING=ON, ond5adabaeStrings.cppandGuestWideStrings.cppbuild without warnings, also with-Wall -Wextra.ctest -E 'agc|shader|recompiler|Vulkan|vulkan|video_out': 197/197 passed, includingguest_wide_stringsandguest_wide_formatting. GPU tests not run.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-07T13:54:42Z.
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.
main)docs/dev/TechnicalDebt.mdL211docs/dev/TechnicalDebt.mdL211wcschr_nid_postfixwcscmp_nid_postfixwcscpy_nid_postfixwcslen_nid_postfixwcsncmp_nid_postfixwcsrchr_nid_postfixwcsspn_nid_postfixwmemchr_nid_postfixwmemcmp_nid_postfixwmemset_nid_postfixdocs/dev/TechnicalDebt.mdL211Imported from boykopovar/AnyPS5. Originally posted by fisherjoey on 2026-10-08T05:24:37Z.
This looks like the same change as #1126: both add
wcslen_nid_postfix,wcscpy_nid_postfixandwmemcpy_nid_postfixtolibc/src/Strings.cppfor 16-bit guest wide strings, with aGuestWideStrings.cpptest under the sameguest_wide_stringsctest name. Linking so they can be compared.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-08T07:57:40Z.
Checked the 15 rewrites against the C semantics (unsigned unit comparison,
wcsncpypadding/truncation, overlappingwmemmove, empty needle inwcsstr, terminator inwcschr/wcsrchr) and ranguest_wide_stringson Linux: it passes, and fails withStrings.cppreverted, so it covers the 32-bit hostwchar_tcase. Full ctest green (424/424).Only issue was a TechnicalDebt.md adjacency conflict with main; I rebased and kept all lines. Merging once CI is green on the rebased head.
#1126 is the follow-up and will need a rebase after this lands.