fix(libc): use the Annex K size limit and codes of the PS5 libc, as measured on a PS5 #8965

Open
ionut27001 wants to merge 4 commits from upstream-pr/8965 into main
ionut27001 commented 2026-10-21 07:39:53 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ionut27001 on 2026-10-21T07:39:53Z.


What

The Annex K size limit and violation codes of the PS5 libc, as measured in a payload process on a PS5 (firmware 12.70), differ from the ones the copy functions in core/libs/prx/libc/src/Strings.cpp used.

  • memcpy_s accepts a destination size up to 0x1fffffffffffffff and returns EINVAL (22) from 0x2000000000000000 up (L752-L766); wmemcpy_s has the same limit in elements (L772-L784). That is RSIZE_MAX = 2^61-1 for bytes and for wide elements. This libc used SIZE_MAX >> 1 for bytes and half of that for wide elements, and returned ERANGE (34) above it.
  • strcpy_s with a destination size of SIZE_MAX returns 22 and leaves the destination alone (L787); this libc returned 34.
  • strncpy_s with a count of SIZE_MAX, a destination size of 4 and a 6-character source returns 22 with dest[0] set to zero (L791); this libc returned 34. The code checks the count against RSIZE_MAX before whether the string fits; the measured call has a source that does not fit, so it does not show the case of a source that fits.

What changed: one RsizeMax of 2^61-1 for the byte and wide Annex K functions of Strings.cpp, EINVAL instead of ERANGE for a destination size above it, and the count check in strncpy_s (and so in strcpy_s, which now passes RSIZE_MAX as its count). memmove_s, wmemmove_s, strncat_s, wcsncpy_s and wcsncat_s take the same limit and the same EINVAL; strcat_s and wcscat_s follow through them. Those siblings were not measured, so that is an inference from the measured functions, and the debt entry says so. memset_s keeps its own limit.

Unchanged and matching the measurement: a count above the destination size returns 34 and zero-fills the destination (memcpy_s, L767); an overlapping source, a null destination and a null source return 22, with the destination zero-filled for the overlap and for a null source with a count of 4 (L768-L771); strcpy_s returns 34 with dest[0] set to zero when the source does not fit, 22 for a destination size of 0 and 22 with dest[0] set to zero for a null source (L785, L786, L788); strncpy_s returns 0 for a count of 3 into a destination size of 4 and 34 with dest[0] set to zero for a count of 4 (L789, L790).

fopen_s needed no change: the errno of the failed open, the null file pointer on failure and 22 for a null path, mode or file pointer are what L734-L746 show. The test pins them.

What is not done: the registered constraint handler is still not called for a violation. The measurement shows one call per violation for memcpy_s, wmemcpy_s, strcpy_s, strncpy_s and fopen_s with a counting handler installed, but not what the default handler does, so adding calls would change what a title sees. The debt entries for the Annex K functions and fopen_s are cut to that and to the unmeasured parts.

Relation to open pull requests:

  • #7841 adds the Annex K functions libc still lacks (bsearch_s, wcstok_s, wctomb_s, wcrtomb_s, mbstowcs_s, mbsrtowcs_s, gets_s, abort_handler_s) in a new BoundsChecking.cpp. This pull request changes none of them and only functions already in Strings.cpp, so it does not re-implement anything #7841 adds, and it does not depend on it. #7841 uses its own rsizeMax of 2^61-1, which agrees with the measured limit. The two share core/libs/prx/libc/CMakeLists.txt and docs/dev/debt/libc.md in different hunks; git apply --check of #7841's diff on this branch is clean.
  • #7979 (overlap checks in strncpy_s and strncat_s) edits other lines of the same two functions; its diff applies cleanly on this branch.
  • #7952 adds wcscpy_s to the same Annex K debt entry, so whichever of the two lands second rebases that line. Its wcscpy_s still uses the old limit and ERANGE.

Tested

  • Windows 11, MinGW-w64 GCC 15.2.0 (WinLibs), head 65c7c4abe4 (main merged at 3fea2a937b), the test now declaring the functions through prx/libc/include/Api.hpp (FileStream*, char16_t*, size_t) instead of local declarations: ctest --test-dir build -R "^(guest_libc_annexk_rsizemax|guest_strings|guest_wide_strings)$" ran twice: 3 of 3 passed both times.
  • Earlier, at head cd64f65e6 rebased onto main, ctest -R "guest_libc|guest_strings|guest_wide_strings|guest_string" ran twice: 8 of 8 passed both times.
  • With libc/src/Strings.cpp restored from the previous commit and rebuilt, guest_libc_annexk_rsizemax, guest_strings and guest_wide_strings fail (3 of 8); with the file restored they pass again.
  • The build had one failing target that this change does not touch: the AGC test agc_driver_image_array_window_past_layer_limit_tests does not compile with MinGW (alignas(65536)).
  • python tools/check_conventions.py --base origin/main passes at the head of this pull request.
  • No title and no homebrew was run. The measured values are from a payload process on one PS5 (firmware 12.70); a title process was not measured.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4948124389 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8965). Originally posted by [ionut27001](https://github.com/ionut27001) on 2026-10-21T07:39:53Z. --- ### What The Annex K size limit and violation codes of the PS5 libc, as measured in a payload process on a PS5 (firmware 12.70), differ from the ones the copy functions in `core/libs/prx/libc/src/Strings.cpp` used. - `memcpy_s` accepts a destination size up to `0x1fffffffffffffff` and returns `EINVAL` (22) from `0x2000000000000000` up (L752-L766); `wmemcpy_s` has the same limit in elements (L772-L784). That is `RSIZE_MAX` = 2^61-1 for bytes and for wide elements. This libc used `SIZE_MAX >> 1` for bytes and half of that for wide elements, and returned `ERANGE` (34) above it. - `strcpy_s` with a destination size of `SIZE_MAX` returns 22 and leaves the destination alone (L787); this libc returned 34. - `strncpy_s` with a count of `SIZE_MAX`, a destination size of 4 and a 6-character source returns 22 with `dest[0]` set to zero (L791); this libc returned 34. The code checks the count against `RSIZE_MAX` before whether the string fits; the measured call has a source that does not fit, so it does not show the case of a source that fits. What changed: one `RsizeMax` of 2^61-1 for the byte and wide Annex K functions of `Strings.cpp`, `EINVAL` instead of `ERANGE` for a destination size above it, and the count check in `strncpy_s` (and so in `strcpy_s`, which now passes `RSIZE_MAX` as its count). `memmove_s`, `wmemmove_s`, `strncat_s`, `wcsncpy_s` and `wcsncat_s` take the same limit and the same `EINVAL`; `strcat_s` and `wcscat_s` follow through them. Those siblings were not measured, so that is an inference from the measured functions, and the debt entry says so. `memset_s` keeps its own limit. Unchanged and matching the measurement: a count above the destination size returns 34 and zero-fills the destination (`memcpy_s`, L767); an overlapping source, a null destination and a null source return 22, with the destination zero-filled for the overlap and for a null source with a count of 4 (L768-L771); `strcpy_s` returns 34 with `dest[0]` set to zero when the source does not fit, 22 for a destination size of 0 and 22 with `dest[0]` set to zero for a null source (L785, L786, L788); `strncpy_s` returns 0 for a count of 3 into a destination size of 4 and 34 with `dest[0]` set to zero for a count of 4 (L789, L790). `fopen_s` needed no change: the errno of the failed open, the null file pointer on failure and 22 for a null path, mode or file pointer are what L734-L746 show. The test pins them. What is not done: the registered constraint handler is still not called for a violation. The measurement shows one call per violation for `memcpy_s`, `wmemcpy_s`, `strcpy_s`, `strncpy_s` and `fopen_s` with a counting handler installed, but not what the default handler does, so adding calls would change what a title sees. The debt entries for the Annex K functions and `fopen_s` are cut to that and to the unmeasured parts. Relation to open pull requests: - #7841 adds the Annex K functions libc still lacks (`bsearch_s`, `wcstok_s`, `wctomb_s`, `wcrtomb_s`, `mbstowcs_s`, `mbsrtowcs_s`, `gets_s`, `abort_handler_s`) in a new `BoundsChecking.cpp`. This pull request changes none of them and only functions already in `Strings.cpp`, so it does not re-implement anything #7841 adds, and it does not depend on it. #7841 uses its own `rsizeMax` of 2^61-1, which agrees with the measured limit. The two share `core/libs/prx/libc/CMakeLists.txt` and `docs/dev/debt/libc.md` in different hunks; `git apply --check` of #7841's diff on this branch is clean. - #7979 (overlap checks in `strncpy_s` and `strncat_s`) edits other lines of the same two functions; its diff applies cleanly on this branch. - #7952 adds `wcscpy_s` to the same Annex K debt entry, so whichever of the two lands second rebases that line. Its `wcscpy_s` still uses the old limit and `ERANGE`. ### Tested <!-- OS, title or homebrew, what was checked. "Not tested" is a valid answer. A performance change: the summary lines of main and of this PR from the same machine and scene, with the traces attached, captured as the Performance report issue form describes. --> - Windows 11, MinGW-w64 GCC 15.2.0 (WinLibs), head 65c7c4abe4 (main merged at 3fea2a937b), the test now declaring the functions through `prx/libc/include/Api.hpp` (`FileStream*`, `char16_t*`, `size_t`) instead of local declarations: `ctest --test-dir build -R "^(guest_libc_annexk_rsizemax|guest_strings|guest_wide_strings)$"` ran twice: 3 of 3 passed both times. - Earlier, at head cd64f65e6 rebased onto main, `ctest -R "guest_libc|guest_strings|guest_wide_strings|guest_string"` ran twice: 8 of 8 passed both times. - With `libc/src/Strings.cpp` restored from the previous commit and rebuilt, `guest_libc_annexk_rsizemax`, `guest_strings` and `guest_wide_strings` fail (3 of 8); with the file restored they pass again. - The build had one failing target that this change does not touch: the AGC test `agc_driver_image_array_window_past_layer_limit_tests` does not compile with MinGW (`alignas(65536)`). - `python tools/check_conventions.py --base origin/main` passes at the head of this pull request. - No title and no homebrew was run. The measured values are from a payload process on one PS5 (firmware 12.70); a title process was not measured. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
ionut27001 commented 2026-10-21 07:40:02 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ionut27001 on 2026-10-21T07:40:02Z.


Probe lines the body refers to (p83, payload process on a PS5, firmware 12.70; log lines 734-791, quoted unchanged):

case fopen_s missing_read ret=2 errno_after=2 file_null=1 file_untouched=0 handler=0
case fopen_s existing_read ret=0 errno_after=0 file_null=0 file_untouched=0 handler=0
case fopen_s create_write ret=0 errno_after=0 file_null=0 file_untouched=0 handler=0
case fopen_s exclusive_on_existing_wx ret=17 errno_after=17 file_null=1 file_untouched=0 handler=0
case fopen_s exclusive_on_new_wx ret=0 errno_after=0 file_null=0 file_untouched=0 handler=0
case fopen_s invalid_mode_z ret=22 errno_after=22 file_null=1 file_untouched=0 handler=0
case fopen_s empty_mode ret=22 errno_after=22 file_null=1 file_untouched=0 handler=0
case fopen_s directory_read ret=0 errno_after=0 file_null=0 file_untouched=0 handler=0
case fopen_s directory_write ret=21 errno_after=21 file_null=1 file_untouched=0 handler=0
case fopen_s missing_read_plus ret=2 errno_after=2 file_null=1 file_untouched=0 handler=0
case fopen_s null_path ret=22 file_null=1 handler=1
case fopen_s null_mode ret=22 file_null=1 handler=1
case fopen_s null_file_pointer ret=22 handler=1
resolve sym=set_constraint_handler_s module=libSceLibcInternal.sprx exported=yes
resolve sym=memcpy_s module=libSceLibcInternal.sprx exported=yes
resolve sym=wmemcpy_s module=libSceLibcInternal.sprx exported=yes
resolve sym=strcpy_s module=libSceLibcInternal.sprx exported=yes
resolve sym=strncpy_s module=libSceLibcInternal.sprx exported=yes
case annexk memcpy_s destsz=0x40 n=1 ret=0 copied=1 handler=0
case annexk memcpy_s destsz=0x1000 n=1 ret=0 copied=1 handler=0
case annexk memcpy_s destsz=0x100000 n=1 ret=0 copied=1 handler=0
case annexk memcpy_s destsz=0x40000000 n=1 ret=0 copied=1 handler=0
case annexk memcpy_s destsz=0x7fffffff n=1 ret=0 copied=1 handler=0
case annexk memcpy_s destsz=0x80000000 n=1 ret=0 copied=1 handler=0
case annexk memcpy_s destsz=0xffffffff n=1 ret=0 copied=1 handler=0
case annexk memcpy_s destsz=0x100000000 n=1 ret=0 copied=1 handler=0
case annexk memcpy_s destsz=0x10000000000 n=1 ret=0 copied=1 handler=0
case annexk memcpy_s destsz=0x4000000000000000 n=1 ret=22 copied=0 handler=1
case annexk memcpy_s destsz=0x7ffffffffffffffe n=1 ret=22 copied=0 handler=1
case annexk memcpy_s destsz=0x7fffffffffffffff n=1 ret=22 copied=0 handler=1
case annexk memcpy_s destsz=0x8000000000000000 n=1 ret=22 copied=0 handler=1
case annexk memcpy_s destsz=0xffffffffffffffff n=1 ret=22 copied=0 handler=1
case annexk memcpy_s largest_accepted_destsz=0x1fffffffffffffff first_refused_destsz=0x2000000000000000
case annexk memcpy_s n_above_destsz ret=34 dest_first8=000000005a5a5a5a handler=1
case annexk memcpy_s overlap ret=22 dest_first8=0000000000000000 handler=1
case annexk memcpy_s null_dest ret=22 handler=1
case annexk memcpy_s null_src n4 ret=22 dest_first8=0000000000000000 handler=1
case annexk memcpy_s null_src n0 ret=22 handler=1
case annexk wmemcpy_s destsz=0x20 n=1 ret=0 copied=1 handler=0
case annexk wmemcpy_s destsz=0x100000 n=1 ret=0 copied=1 handler=0
case annexk wmemcpy_s destsz=0x7fffffff n=1 ret=0 copied=1 handler=0
case annexk wmemcpy_s destsz=0x80000000 n=1 ret=0 copied=1 handler=0
case annexk wmemcpy_s destsz=0x100000000 n=1 ret=0 copied=1 handler=0
case annexk wmemcpy_s destsz=0x3ffffffffffffffe n=1 ret=22 copied=0 handler=1
case annexk wmemcpy_s destsz=0x3fffffffffffffff n=1 ret=22 copied=0 handler=1
case annexk wmemcpy_s destsz=0x4000000000000000 n=1 ret=22 copied=0 handler=1
case annexk wmemcpy_s destsz=0x7ffffffffffffffe n=1 ret=22 copied=0 handler=1
case annexk wmemcpy_s destsz=0x7fffffffffffffff n=1 ret=22 copied=0 handler=1
case annexk wmemcpy_s destsz=0x8000000000000000 n=1 ret=22 copied=0 handler=1
case annexk wmemcpy_s destsz=0xffffffffffffffff n=1 ret=22 copied=0 handler=1
case annexk wmemcpy_s largest_accepted_destsz=0x1fffffffffffffff first_refused_destsz=0x2000000000000000
case annexk strcpy_s destsz4_src6 ret=34 dest_first8=005a5a5a5a5a5a5a handler=1
case annexk strcpy_s destsz0 ret=22 dest_first4=5a5a5a5a handler=1
case annexk strcpy_s destsz_size_max ret=22 dest_first4=5a5a5a5a handler=1
case annexk strcpy_s null_src ret=22 dest_first4=005a5a5a handler=1
case annexk strncpy_s destsz4_n3 ret=0 dest_first8=616263005a5a5a5a handler=0
case annexk strncpy_s destsz4_n4 ret=34 dest_first8=005a5a5a5a5a5a5a handler=1
case annexk strncpy_s destsz4_n_trunc ret=22 dest_first8=005a5a5a5a5a5a5a handler=1
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6310730670 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8965#issuecomment-6310730670). Originally posted by [ionut27001](https://github.com/ionut27001) on 2026-10-21T07:40:02Z. --- Probe lines the body refers to (p83, payload process on a PS5, firmware 12.70; log lines 734-791, quoted unchanged): ``` case fopen_s missing_read ret=2 errno_after=2 file_null=1 file_untouched=0 handler=0 case fopen_s existing_read ret=0 errno_after=0 file_null=0 file_untouched=0 handler=0 case fopen_s create_write ret=0 errno_after=0 file_null=0 file_untouched=0 handler=0 case fopen_s exclusive_on_existing_wx ret=17 errno_after=17 file_null=1 file_untouched=0 handler=0 case fopen_s exclusive_on_new_wx ret=0 errno_after=0 file_null=0 file_untouched=0 handler=0 case fopen_s invalid_mode_z ret=22 errno_after=22 file_null=1 file_untouched=0 handler=0 case fopen_s empty_mode ret=22 errno_after=22 file_null=1 file_untouched=0 handler=0 case fopen_s directory_read ret=0 errno_after=0 file_null=0 file_untouched=0 handler=0 case fopen_s directory_write ret=21 errno_after=21 file_null=1 file_untouched=0 handler=0 case fopen_s missing_read_plus ret=2 errno_after=2 file_null=1 file_untouched=0 handler=0 case fopen_s null_path ret=22 file_null=1 handler=1 case fopen_s null_mode ret=22 file_null=1 handler=1 case fopen_s null_file_pointer ret=22 handler=1 resolve sym=set_constraint_handler_s module=libSceLibcInternal.sprx exported=yes resolve sym=memcpy_s module=libSceLibcInternal.sprx exported=yes resolve sym=wmemcpy_s module=libSceLibcInternal.sprx exported=yes resolve sym=strcpy_s module=libSceLibcInternal.sprx exported=yes resolve sym=strncpy_s module=libSceLibcInternal.sprx exported=yes case annexk memcpy_s destsz=0x40 n=1 ret=0 copied=1 handler=0 case annexk memcpy_s destsz=0x1000 n=1 ret=0 copied=1 handler=0 case annexk memcpy_s destsz=0x100000 n=1 ret=0 copied=1 handler=0 case annexk memcpy_s destsz=0x40000000 n=1 ret=0 copied=1 handler=0 case annexk memcpy_s destsz=0x7fffffff n=1 ret=0 copied=1 handler=0 case annexk memcpy_s destsz=0x80000000 n=1 ret=0 copied=1 handler=0 case annexk memcpy_s destsz=0xffffffff n=1 ret=0 copied=1 handler=0 case annexk memcpy_s destsz=0x100000000 n=1 ret=0 copied=1 handler=0 case annexk memcpy_s destsz=0x10000000000 n=1 ret=0 copied=1 handler=0 case annexk memcpy_s destsz=0x4000000000000000 n=1 ret=22 copied=0 handler=1 case annexk memcpy_s destsz=0x7ffffffffffffffe n=1 ret=22 copied=0 handler=1 case annexk memcpy_s destsz=0x7fffffffffffffff n=1 ret=22 copied=0 handler=1 case annexk memcpy_s destsz=0x8000000000000000 n=1 ret=22 copied=0 handler=1 case annexk memcpy_s destsz=0xffffffffffffffff n=1 ret=22 copied=0 handler=1 case annexk memcpy_s largest_accepted_destsz=0x1fffffffffffffff first_refused_destsz=0x2000000000000000 case annexk memcpy_s n_above_destsz ret=34 dest_first8=000000005a5a5a5a handler=1 case annexk memcpy_s overlap ret=22 dest_first8=0000000000000000 handler=1 case annexk memcpy_s null_dest ret=22 handler=1 case annexk memcpy_s null_src n4 ret=22 dest_first8=0000000000000000 handler=1 case annexk memcpy_s null_src n0 ret=22 handler=1 case annexk wmemcpy_s destsz=0x20 n=1 ret=0 copied=1 handler=0 case annexk wmemcpy_s destsz=0x100000 n=1 ret=0 copied=1 handler=0 case annexk wmemcpy_s destsz=0x7fffffff n=1 ret=0 copied=1 handler=0 case annexk wmemcpy_s destsz=0x80000000 n=1 ret=0 copied=1 handler=0 case annexk wmemcpy_s destsz=0x100000000 n=1 ret=0 copied=1 handler=0 case annexk wmemcpy_s destsz=0x3ffffffffffffffe n=1 ret=22 copied=0 handler=1 case annexk wmemcpy_s destsz=0x3fffffffffffffff n=1 ret=22 copied=0 handler=1 case annexk wmemcpy_s destsz=0x4000000000000000 n=1 ret=22 copied=0 handler=1 case annexk wmemcpy_s destsz=0x7ffffffffffffffe n=1 ret=22 copied=0 handler=1 case annexk wmemcpy_s destsz=0x7fffffffffffffff n=1 ret=22 copied=0 handler=1 case annexk wmemcpy_s destsz=0x8000000000000000 n=1 ret=22 copied=0 handler=1 case annexk wmemcpy_s destsz=0xffffffffffffffff n=1 ret=22 copied=0 handler=1 case annexk wmemcpy_s largest_accepted_destsz=0x1fffffffffffffff first_refused_destsz=0x2000000000000000 case annexk strcpy_s destsz4_src6 ret=34 dest_first8=005a5a5a5a5a5a5a handler=1 case annexk strcpy_s destsz0 ret=22 dest_first4=5a5a5a5a handler=1 case annexk strcpy_s destsz_size_max ret=22 dest_first4=5a5a5a5a handler=1 case annexk strcpy_s null_src ret=22 dest_first4=005a5a5a handler=1 case annexk strncpy_s destsz4_n3 ret=0 dest_first8=616263005a5a5a5a handler=0 case annexk strncpy_s destsz4_n4 ret=34 dest_first8=005a5a5a5a5a5a5a handler=1 case annexk strncpy_s destsz4_n_trunc ret=22 dest_first8=005a5a5a5a5a5a5a handler=1 ```
harisibrar1 commented 2026-10-24 13:39:22 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by harisibrar1 on 2026-10-24T13:39:22Z.

Review: COMMENTED


Checked against main 522e32e3b6 and the 12.70 log in this PR, plus #10270's console gist (dcadb97109bb78711ff3f7ba1dc479ed, firmware 13.60):

  • The 2^61-1 limit and EINVAL for an oversized destsz match your log, #10270's psafestr2 boundary search, and the rsizeMax already in main's BoundsChecking.cpp:29. It still merges cleanly with main.
  • #10270 now changes the same twelve functions to the same limit and EINVAL, also calls the constraint handler and covers wcscpy_s, so the two will conflict throughout Strings.cpp, GuestStrings.cpp, GuestWideStrings.cpp and libc.md. Could you coordinate with @orezraey on which one lands? The fopen_s test and debt rewrite here look like the part #10270 doesn't cover.
  • Oversized counts: #10270's gist shows memcpy_s(d, 4, "abc", 1<<61) returning 22 with the destination zeroed (psafestr3 mcpy_count_big), while this branch returns 34 for that call (count > destsz). strncat_s(d="ab", 8, "c", 1<<61) returns 22 with d[0]=0 on the console (ncat_count_big), but 0 with "abc" here. psafestr3/4 show the same 22 for memmove_s, wcsncpy_s, wcsncat_s and wmemcpy_s, so the debt line saying those functions "accept one" would describe a known divergence. That run used a different firmware from yours, though.
  • wcscpy_s is on main now (SonyCrt.hpp:140, used by WideConversion.cpp:37 and libSceAmpr) with the old (SIZE_MAX >> 1) / 2 limit and ERANGE. With this PR, wcscpy_s(d, 0x2000000000000000, u"a") returns 0 while wcsncpy_s(d, 0x2000000000000000, u"a", 1) returns 22.
  • Small one: the body still describes #7841 as open, but it's merged as BoundsChecking.cpp.

Reviewed with AI assistance (Claude Code); the checks above were run locally on my machine.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5638442294 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8965#pullrequestreview-5638442294). Originally posted by [harisibrar1](https://github.com/harisibrar1) on 2026-10-24T13:39:22Z. **Review:** COMMENTED --- Checked against main 522e32e3b6 and the 12.70 log in this PR, plus #10270's console gist (dcadb97109bb78711ff3f7ba1dc479ed, firmware 13.60): - The 2^61-1 limit and EINVAL for an oversized destsz match your log, #10270's psafestr2 boundary search, and the `rsizeMax` already in main's BoundsChecking.cpp:29. It still merges cleanly with main. - #10270 now changes the same twelve functions to the same limit and EINVAL, also calls the constraint handler and covers wcscpy_s, so the two will conflict throughout Strings.cpp, GuestStrings.cpp, GuestWideStrings.cpp and libc.md. Could you coordinate with @orezraey on which one lands? The fopen_s test and debt rewrite here look like the part #10270 doesn't cover. - Oversized counts: #10270's gist shows `memcpy_s(d, 4, "abc", 1<<61)` returning 22 with the destination zeroed (psafestr3 `mcpy_count_big`), while this branch returns 34 for that call (`count > destsz`). `strncat_s(d="ab", 8, "c", 1<<61)` returns 22 with d[0]=0 on the console (`ncat_count_big`), but 0 with "abc" here. psafestr3/4 show the same 22 for memmove_s, wcsncpy_s, wcsncat_s and wmemcpy_s, so the debt line saying those functions "accept one" would describe a known divergence. That run used a different firmware from yours, though. - wcscpy_s is on main now (SonyCrt.hpp:140, used by WideConversion.cpp:37 and libSceAmpr) with the old `(SIZE_MAX >> 1) / 2` limit and ERANGE. With this PR, `wcscpy_s(d, 0x2000000000000000, u"a")` returns 0 while `wcsncpy_s(d, 0x2000000000000000, u"a", 1)` returns 22. - Small one: the body still describes #7841 as open, but it's merged as BoundsChecking.cpp. Reviewed with AI assistance (Claude Code); the checks above were run locally on my machine.
MarcZX10 commented 2026-11-23 02:32:45 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-23T02:32:45Z.

Review: APPROVED


Reviewed — looks good

Nothing blocks this change; the review evidence supports merging, with the unmeasured sibling behavior clearly marked as inference.

What I ran

Reviewed head 65c7c4abe424979778bae6f529d2afee8a03086f using the prepared diff and repo_read.py. No commands or tests were run in this review; test results below are author-reported.

Results

Check Result Note
Changed code review passed All six reviewed files were read
Tests in this review not run Windows results are author-reported
Console measurement not run Description reports payload measurements

Findings

Blocking

None.

Non-blocking

None.

Not verified

No files were excluded: files.json was not available at the supplied review path, and the manifest marks all six changed files as included. The test suite, convention check, PS5 payload measurements, and title behavior were not independently verified. The description identifies memmove_s, wmemmove_s, strncat_s, wcsncpy_s, and wcsncat_s limits and error codes as inferred from measured siblings.

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6015943175 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8965#pullrequestreview-6015943175). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-23T02:32:45Z. **Review:** APPROVED --- # Reviewed — looks good Nothing blocks this change; the review evidence supports merging, with the unmeasured sibling behavior clearly marked as inference. ## What I ran Reviewed head `65c7c4abe424979778bae6f529d2afee8a03086f` using the prepared diff and `repo_read.py`. No commands or tests were run in this review; test results below are author-reported. ## Results | Check | Result | Note | |---|---|---| | Changed code review | passed | All six reviewed files were read | | Tests in this review | not run | Windows results are author-reported | | Console measurement | not run | Description reports payload measurements | ## Findings ### Blocking None. ### Non-blocking None. ## Not verified No files were excluded: `files.json` was not available at the supplied review path, and the manifest marks all six changed files as included. The test suite, convention check, PS5 payload measurements, and title behavior were not independently verified. The description identifies `memmove_s`, `wmemmove_s`, `strncat_s`, `wcsncpy_s`, and `wcsncat_s` limits and error codes as inferred from measured siblings. ## To get this to a good state Nothing is required.
ligmaSec commented 2026-12-03 13:36:38 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T13:36:38Z.

Review: COMMENTED


Built the changed sources against the existing Linux runtime. The focused Annex K size-limit fixture passed. The broader wide-string fixture aborted in this standalone setup.

AI-assisted: yes.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6170841003 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8965#pullrequestreview-6170841003). Originally posted by [ligmaSec](https://github.com/ligmaSec) on 2026-12-03T13:36:38Z. **Review:** COMMENTED --- Built the changed sources against the existing Linux runtime. The focused Annex K size-limit fixture passed. The broader wide-string fixture aborted in this standalone setup. AI-assisted: yes.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/8965:upstream-pr/8965'
git switch 'upstream-pr/8965'

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.

git switch 'main'
git merge --no-ff 'upstream-pr/8965'
git switch 'upstream-pr/8965'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/8965'
git switch 'upstream-pr/8965'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/8965'
git switch 'main'
git merge --squash 'upstream-pr/8965'
git switch 'main'
git merge --ff-only 'upstream-pr/8965'
git switch 'main'
git merge 'upstream-pr/8965'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!8965
No description provided.