fix(libc): check asctime_s and ctime_s arguments as titles' libc.prx does #12574

Merged
JJenkx merged 7 commits from upstream-pr/12574 into main 2026-11-13 11:50:23 +00:00
JJenkx commented 2026-10-28 21:08:31 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by JJenkx on 2026-10-28T21:08:31Z.


Current-main integration — 2026-11-12. Head 079738c3f9 merges main c85dcfd005 (063c638608) and adds one test commit.

  • Conflicts:
    • SonyCrt.hpp: main's out-of-line handler declarations are taken unchanged.
    • docs/dev/debt/libc.md: this PR's asctime_s/ctime_s wording is kept, and the per-module handler sentence that main removed stays removed.
  • Test change: since main shares the handler, every sceAmprAsctimeS violation made while guest_crt's recording handler is installed now reaches that handler too. With the merge alone, guest_crt failed at line 230 in 3 of 3 runs. The new commit checks each of those seven calls with its own message.
  • Windows 11 22621, MinGW-w64 GCC 15.2 UCRT, Release: guest_crt, guest_time_conversion, guest_mktime and guest_time_extras pass in 3 of 3 runs. check_conventions.py passes.

Current-main integration — 2026-11-05. Exact head b5644e160f5596522221f2df822a511fd4fe9e12 retains previous public 25ab50c9e70bdaced8575d715ae4422faf8de704 and tested main 6d173c1a19788ff69d43b3d0ca62833e312ef939 as ancestors. The whole SonyCrt.hpp remains byte-identical to the previous qualified head, retaining time checks, padding/output behavior and ELF per-module hidden handler accessors. Actual libc and Ampr were rebuilt coherently.

Linux x86-64, GCC16.2.1, Ninja Release: actual production modules and focused fixture owners rebuilt; 3/3 runtime tests pass, zero skips: guest_crt, guest_time_conversion, guest_time_extras. Matching pinned main passes all25 selected baseline groups. Production NID patching, conventions/whitespace, and MinGW syntax for SonyCrt.hpp pass.

Public-header audit: failed on both pinned main and this head with the same five missing WKSecurityOrigin* declarations (Create, CopyToString, CopyHost, CopyProtocol, GetPort), with no additional declaration errors. The failure is retained in the logs; no all-green header/full-suite claim is made. The concrete shared-main repair is #16010, exact head 545e24b2ee2e549001421f7fc9f87ff801f3423c. Its independent qualification reports a green audit of 406 libraries/30,572 exports and two standalone units compiled by each of GCC and MinGW. A maintainer still needs to merge that repair and rerun the affected checks; this unmodified qualification tree is not relabelled header-green.

The older-main Windows DepthSurface::createSampleShadow allocation compile error is already corrected by merged #15855. This head contains that fix, and its DepthSurface.cpp/ImageMemory.hpp blobs match the fixing source. The fix’s hosted Windows build passed; that is attributed upstream evidence, not a Windows build/runtime result for this head. No duplicate AGC change was added. A final merge preview against newer main 7ad9749ed0311cc91d69bc7c690d09c92b9d42d0 is clean; qualification remains pinned to 6d173c1a19788ff69d43b3d0ca62833e312ef939.

Source/parent/provider/gitlink proofs, commands, raw logs, JUnit, hashes and known baseline failure. Historical platform, module-reference and performance reports below retain their original pins; no new Windows/macOS, SDK/physical-console, title/GPU or performance run.

Earlier pinned reports and the contribution template follow.

What

asctime_s and ctime_s (libc, and libSceAmpr through the shared header) now check their arguments the way the libc.prx that titles ship does. Every violation calls the constraint handler with EINVAL, as the other _s functions in this module already do. On main these two returned EINVAL without calling it.

Measured rules, applied in this order (the handler's pointer argument is always null):

  1. A null buffer, a size of 0, or a size above SIZE_MAX >> 3 (from 2^61): message "asctime_s: bad destination argument" (or ctime_s), and nothing is written.
  2. A size under 26, a null time, or a field out of range: message "asctime_s: bad argument", and '\0' is stored in the first byte. ctime_s checks the size before it converts the time.

The field limits were already right, except that tm_yday outside 0 to 365 is now rejected too. Two output fixes:

  • The year is zero-padded (0957), as plain asctime already does.
  • From a size of 2^32 up, main returned 0 without writing anything, because snprintf rejected the size. The text is now always written with a size of 26.

Prior work. @ivica00 read these same rules from the disassembly of a title's libc.prx in #8711, which they closed on 2026-10-21 after it needed a rebase. That PR also covered strtok_s and _Thrd_id. I found it only after opening this PR. The rules here were measured independently by running the titles' code, and they agree with that description: destinations of 0 or from 2^61 are rejected without writing, the destination is cleared on a later argument failure, EINVAL with a null pointer argument, and four-digit years.

Fulfilled dependency: #9935 reached main through merged #10270, whose returning default-handler behavior is retained alongside this PR’s time-constraint rules. The earlier agreed order is fulfilled; the old debt-line conflict has been resolved without reverting main’s handler behavior.

Superseded (2026-11-12): main 3728cf4c67 moved the Sony CRT handler state into SonyCrt.cpp and now shares it between libc and libSceAmpr. This PR takes main's version and no longer changes the handler accessors.

Tested

Current-main refresh — 2026-11-04. Head 25ab50c9e70bdaced8575d715ae4422faf8de704 merges main 9ab6a281ea61c9e62a7eb07eb4cef8f19ede1c5c while retaining the prior public head as an ancestor. Main’s newer code, regression fixtures and debt entries are preserved alongside this topic.

Linux x86-64, GCC16.2.1, Ninja Release: actual libc, libkernel and libSceAmpr CMake owners rebuilt coherently. guest_crt, guest_time_conversion, guest_mktime each pass three consecutive runs (9 passes, zero skips). The same groups pass three times on pinned main. Public-header audit and conventions pass. Original licence-notice trailing whitespace is retained where present. The scoped recipe reuses frozen ZArchive/zstd providers; this is not a whole-project build. No new Windows, bundled-SDK, physical-console, title/GPU or FPS measurement is claimed; earlier reports retain their original pins.

Exact source/parent proofs, per-branch patches/input manifests, build and CTest logs/JUnit, library/executable hashes and scoped CMake recipe, SHA-256 97a2377bc996be1690e8853e1ea090a98b5ed808bcc37a15a5cdada5c2e00845 (download verified). AI-assisted: yes (Codex).

Current-main integration — 2026-11-04. Head cec91f3fe5e8f335b89b5dfd6ef16bdf073edbd6 includes main b11c7bf84f5d2f636ff60166cc3371bd071e24d5 and preserves previous public commits and attribution/licence notices. Retains both ELF-hidden module-state accessors and the hardened time/constraint fixtures. Main’s returning default handler is preserved; older time-zone/mutant/module-isolation evidence keeps its original pins.

Linux x86-64, GCC 16.2.1, Ninja Release, BUILD_TESTING=ON: rebuilt actual libc/Ampr and selected executables. guest_crt, guest_time_conversion, guest_mktime each pass 3/3 (9 runtime passes, zero skips); public_headers, conventions and whitespace checks pass. Pinned main passes all 17 selected baseline groups 3/3 (51 passes) plus headers. Before/after dependency checks agree: 34 recursive trees and 31,551 tracked blobs, zero errors; the update=none QuickJS test262 corpus is explicitly excluded from these library inputs.

Source/parent/gitlink proofs, library/test hashes, raw logs/JUnit and head-leased push receipts: qualification archive, SHA-256 7c347f620951ad6f39068740750949212c6412815da094a46a96eca1d15c8bbf (download verified). Older platform, stress, negative-control and reference reports retain their original pins; no new Windows/macOS, full-suite, SDK-module, console, title/GPU or performance claim. AI-assisted: yes (Codex).

Earlier dated qualifications below retain their original source/platform pins.

Current-main refresh — 2026-11-02. Published head af6f89bff19ee5d6d7f782db2163406a49a28327 includes pinned main a4eca2a056bf3bbbec98ab42e9d28163e4ea9cb8. The reviewed SonyCrt.hpp header remains byte-identical to6b2c351, including both ELF hidden inline accessors. Current main’s qsort_s/bsearch_s qualifications remain alongside the time constraint debt. Older four-TZ/mutant/ASan module-isolation evidence keeps its original pins; it was not rerun here.

Rebuilt actual libc/Ampr and selected tests from the final input tree. guest_crt, guest_time_conversion, guest_mktime each pass three consecutive runs: 9 runtime passes, zero skips, plus public_headers. Conventions and whitespace pass. Source/input manifests, exact dependencies, library/test hashes, logs/JUnit and head-leased push receipts are attached. The same pinned main passes 18 selected groups three times (54 runtime passes) plus headers. All 34 recursive dependency trees/31,551 tracked blobs verify with zero errors; QuickJS’s update=none test262 corpus is explicitly excluded because it is not a library build input.

Linux-7.2.11-arch1-1-x86_64-with-glibc2.44, Ryzen 9 7950X, GCC 16.2.1, Ninja Release, BUILD_TESTING=ON. Focused Linux CPU qualification only. Older Windows/module/reference reports retain their original pins; no fresh Windows/macOS, SDK-module, console, title/GPU or speed claim. AI-assisted: yes (Codex).

Evidence: https://github.com/JJenkx/AnyPS5/releases/download/linux-validation-20261023/math-six-main-a4eca-linux-extra10321-20261102.tar.gz; SHA-256 525ccb31a5d3d0f5adced5fda58818d8432f06c0afa7290139adb60ae6664b54.

Earlier dated qualifications below retain their recorded source/platform pins.

Windows 11, WinLibs GCC 15.2.0 UCRT r7, Release, main 319621ba2e.

  • Native comparison: a scratch loader calls the titles' functions by NID next to this build's, with the same recording handler installed on both sides. It compares the return value, the handler's calls and error, and the buffer bytes. The messages were recorded from the titles' handler, and guest_crt checks that this build passes the same ones. Results are the same with the libc.prx of PPSA07923 and of PPSA05916.

    check main this PR
    asctime_s, 20,000 random calls: sizes from 0 to above 2^62, null pointers, out-of-range fields 17,930 differ 0
    asctime_s, 108 chosen cases: each size boundary, null pointers, each field limit, years 80 differ 0
    ctime_s, 11 cases that fail before the time conversion 11 differ 0

    The titles' ctime_s calls an import the loader can't provide once it converts a valid time, so the ctime_s paths after localtime_s, including a failing localtime_s, are not compared. The debt entry now says that, instead of "the console's exact checks are not verified".

  • Regression: guest_crt checks each rule, the messages and the year padding. With the previous SonyCrt.hpp it fails (LibcViolation("asctime_s: bad argument")).

  • Test set: guest_crt, guest_safe_errors, guest_bounds_checking, guest_qsort, guest_strftime, guest_mktime and guest_locale pass 3/3. The same holds merged with #9935 (7aa063d91c) for guest_crt, guest_safe_errors, guest_bounds_checking, guest_qsort and guest_strftime. Conventions pass.

Current Linux qualification and module-isolation correction — 2026-10-29

Addressed the review's test hardening and the Linux module-isolation bug it exposed in 6b2c35188f6706790c39f7ba302fc92148fbc7c6.

The added cases require destination-error precedence when the time pointer is also null, short-capacity rejection before converting an unrepresentable timestamp, and each time field's low−1/low/high/high+1 boundaries. The duplicated year assignment is removed. Each of the four proposed incorrect implementation variants now fails at its intended assertion.

The exact original Linux guest_crt also revealed a real prerequisite issue: GNU_UNIQUE handler state coalesced across libc and Ampr, so installing Ampr's handler replaced libc's. The fix gives both internal inline state accessors (handler and mutex) ELF hidden visibility. They retain external inline linkage, sharing state across translation units inside one library while separating the libraries. Guest exports, NIDs and calling conventions are unchanged. The guard leaves PE/Mach-O visibility unchanged. No test counter resets were added to conceal unexpected callbacks.

Qualification on Arch Linux7.2.9 / Ryzen9 7950X / GCC16.2.1 Release uses the actual libc/Ampr libraries: guest_crt passes three repetitions under each of UTC, America/New_York, Pacific/Kiritimati and TZ unset (12 passes). Four actual-header production mutants each fail the intended new assertion. Restoring the candidate passes the focused three-group set three times (9 checks) and restores identical libc and Ampr bytes. Public-header, conventions and whitespace checks pass.

A separate ASan+UBSan harness builds the exact complete header into two DSOs, with two separately compiled translation units per DSO, and alternates setter/invoker translation units. It verifies sharing within each module, separation between modules and preservation of the sibling's handler across resets. The original header fails with “libc handler replaced by Ampr setter”; the fixed header passes. ELF symbol tables confirm the original state is UNIQUE/DEFAULT and fixed handler/mutex state is LOCAL. The full-runtime original failure and all expected negatives are preserved in the evidence. This module-state harness is separate from the actual-library CRT runs.

No new Windows, macOS, title-library or physical-console measurement is claimed. Earlier Windows/title comparisons retain their original pins; the previously documented ctime paths after localtime conversion remain unmeasured.

AI-assisted: yes (Codex).

Evidence: source, raw tests, original failure, sanitizer isolation proof and mutant/restoration receipts, SHA-256 4f0d32cb26b6dfbce3e6c5750990844bc3970fd9b43c3aef2d901ed1050a4477.

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 (#9935 fulfilled through merged #10270; earlier agreed order retained as history)
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes (Claude Code)
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5057727183 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/12574). Originally posted by [JJenkx](https://github.com/JJenkx) on 2026-10-28T21:08:31Z. --- **Current-main integration — 2026-11-12.** Head `079738c3f9` merges main `c85dcfd005` (`063c638608`) and adds one test commit. - **Conflicts:** - `SonyCrt.hpp`: main's out-of-line handler declarations are taken unchanged. - `docs/dev/debt/libc.md`: this PR's `asctime_s`/`ctime_s` wording is kept, and the per-module handler sentence that main removed stays removed. - **Test change:** since main shares the handler, every `sceAmprAsctimeS` violation made while `guest_crt`'s recording handler is installed now reaches that handler too. With the merge alone, `guest_crt` failed at line 230 in 3 of 3 runs. The new commit checks each of those seven calls with its own message. - **Windows 11 22621, MinGW-w64 GCC 15.2 UCRT, Release:** `guest_crt`, `guest_time_conversion`, `guest_mktime` and `guest_time_extras` pass in 3 of 3 runs. `check_conventions.py` passes. <!-- cpu-main6d173-refresh-20261105-12574 --> **Current-main integration — 2026-11-05.** Exact head `b5644e160f5596522221f2df822a511fd4fe9e12` retains previous public `25ab50c9e70bdaced8575d715ae4422faf8de704` and tested main `6d173c1a19788ff69d43b3d0ca62833e312ef939` as ancestors. The whole SonyCrt.hpp remains byte-identical to the previous qualified head, retaining time checks, padding/output behavior and ELF per-module hidden handler accessors. Actual libc and Ampr were rebuilt coherently. Linux x86-64, GCC16.2.1, Ninja Release: actual production modules and focused fixture owners rebuilt; **3/3 runtime tests pass, zero skips**: `guest_crt`, `guest_time_conversion`, `guest_time_extras`. Matching pinned main passes all25 selected baseline groups. Production NID patching, conventions/whitespace, and MinGW syntax for `SonyCrt.hpp` pass. **Public-header audit: failed on both pinned main and this head with the same five missing `WKSecurityOrigin*` declarations** (`Create`, `CopyToString`, `CopyHost`, `CopyProtocol`, `GetPort`), with no additional declaration errors. The failure is retained in the logs; no all-green header/full-suite claim is made. The concrete shared-main repair is [#16010](https://github.com/boykopovar/AnyPS5/pull/16010), exact head `545e24b2ee2e549001421f7fc9f87ff801f3423c`. Its independent qualification reports a green audit of 406 libraries/30,572 exports and two standalone units compiled by each of GCC and MinGW. A maintainer still needs to merge that repair and rerun the affected checks; this unmodified qualification tree is not relabelled header-green. The older-main Windows `DepthSurface::createSampleShadow` allocation compile error is already corrected by merged [#15855](https://github.com/boykopovar/AnyPS5/pull/15855). This head contains that fix, and its DepthSurface.cpp/ImageMemory.hpp blobs match the fixing source. The fix’s [hosted Windows build passed](https://github.com/boykopovar/AnyPS5/actions/runs/41901908835/job/126840906295); that is attributed upstream evidence, not a Windows build/runtime result for this head. No duplicate AGC change was added. A final merge preview against newer main `7ad9749ed0311cc91d69bc7c690d09c92b9d42d0` is clean; qualification remains pinned to `6d173c1a19788ff69d43b3d0ca62833e312ef939`. [Source/parent/provider/gitlink proofs, commands, raw logs, JUnit, hashes and known baseline failure](https://github.com/JJenkx/AnyPS5/releases/download/linux-validation-20261023/cpu5-main6d173-linux-20261105-terminal.tar.gz). Historical platform, module-reference and performance reports below retain their original pins; no new Windows/macOS, SDK/physical-console, title/GPU or performance run. Earlier pinned reports and the contribution template follow. ### What `asctime_s` and `ctime_s` (libc, and libSceAmpr through the shared header) now check their arguments the way the `libc.prx` that titles ship does. Every violation calls the constraint handler with `EINVAL`, as the other `_s` functions in this module already do. On `main` these two returned `EINVAL` without calling it. Measured rules, applied in this order (the handler's pointer argument is always null): 1. A null buffer, a `size` of 0, or a `size` above `SIZE_MAX >> 3` (from 2^61): message `"asctime_s: bad destination argument"` (or `ctime_s`), and nothing is written. 2. A `size` under 26, a null time, or a field out of range: message `"asctime_s: bad argument"`, and `'\0'` is stored in the first byte. `ctime_s` checks the size before it converts the time. The field limits were already right, except that `tm_yday` outside 0 to 365 is now rejected too. Two output fixes: - The year is zero-padded (`0957`), as plain `asctime` already does. - From a `size` of 2^32 up, `main` returned 0 without writing anything, because `snprintf` rejected the size. The text is now always written with a size of 26. **Prior work.** @ivica00 read these same rules from the disassembly of a title's `libc.prx` in #8711, which they closed on 2026-10-21 after it needed a rebase. That PR also covered `strtok_s` and `_Thrd_id`. I found it only after opening this PR. The rules here were measured independently by running the titles' code, and they agree with that description: destinations of 0 or from 2^61 are rejected without writing, the destination is cleared on a later argument failure, `EINVAL` with a null pointer argument, and four-digit years. **Fulfilled dependency:** #9935 reached main through merged #10270, whose returning default-handler behavior is retained alongside this PR’s time-constraint rules. The earlier agreed order is fulfilled; the old debt-line conflict has been resolved without reverting main’s handler behavior. **Superseded (2026-11-12):** main `3728cf4c67` moved the Sony CRT handler state into `SonyCrt.cpp` and now shares it between libc and libSceAmpr. This PR takes main's version and no longer changes the handler accessors. ### Tested <!-- libc-main9ab-refresh-20261104-12574 --> **Current-main refresh — 2026-11-04.** Head `25ab50c9e70bdaced8575d715ae4422faf8de704` merges main `9ab6a281ea61c9e62a7eb07eb4cef8f19ede1c5c` while retaining the prior public head as an ancestor. Main’s newer code, regression fixtures and debt entries are preserved alongside this topic. Linux x86-64, GCC16.2.1, Ninja Release: actual libc, libkernel and libSceAmpr CMake owners rebuilt coherently. `guest_crt`, `guest_time_conversion`, `guest_mktime` each pass three consecutive runs (**9 passes, zero skips**). The same groups pass three times on pinned main. Public-header audit and conventions pass. Original licence-notice trailing whitespace is retained where present. The scoped recipe reuses frozen ZArchive/zstd providers; this is not a whole-project build. No new Windows, bundled-SDK, physical-console, title/GPU or FPS measurement is claimed; earlier reports retain their original pins. [Exact source/parent proofs, per-branch patches/input manifests, build and CTest logs/JUnit, library/executable hashes and scoped CMake recipe](https://github.com/JJenkx/AnyPS5/releases/download/linux-validation-20261023/owned-libc11-main9ab-linux-20261104.tar.gz), SHA-256 `97a2377bc996be1690e8853e1ea090a98b5ed808bcc37a15a5cdada5c2e00845` (download verified). AI-assisted: yes (Codex). **Current-main integration — 2026-11-04.** Head `cec91f3fe5e8f335b89b5dfd6ef16bdf073edbd6` includes main `b11c7bf84f5d2f636ff60166cc3371bd071e24d5` and preserves previous public commits and attribution/licence notices. Retains both ELF-hidden module-state accessors and the hardened time/constraint fixtures. Main’s returning default handler is preserved; older time-zone/mutant/module-isolation evidence keeps its original pins. Linux x86-64, GCC 16.2.1, Ninja Release, BUILD_TESTING=ON: rebuilt actual libc/Ampr and selected executables. `guest_crt`, `guest_time_conversion`, `guest_mktime` each pass 3/3 (**9 runtime passes, zero skips**); `public_headers`, conventions and whitespace checks pass. Pinned main passes all 17 selected baseline groups 3/3 (51 passes) plus headers. Before/after dependency checks agree: 34 recursive trees and 31,551 tracked blobs, zero errors; the update=none QuickJS test262 corpus is explicitly excluded from these library inputs. Source/parent/gitlink proofs, library/test hashes, raw logs/JUnit and head-leased push receipts: [qualification archive](https://github.com/JJenkx/AnyPS5/releases/download/linux-validation-20261023/math-libc10-mainb11c-linux-20261104.tar.gz), SHA-256 `7c347f620951ad6f39068740750949212c6412815da094a46a96eca1d15c8bbf` (download verified). Older platform, stress, negative-control and reference reports retain their original pins; no new Windows/macOS, full-suite, SDK-module, console, title/GPU or performance claim. AI-assisted: yes (Codex). Earlier dated qualifications below retain their original source/platform pins. **Current-main refresh — 2026-11-02.** Published head `af6f89bff19ee5d6d7f782db2163406a49a28327` includes pinned main `a4eca2a056bf3bbbec98ab42e9d28163e4ea9cb8`. The reviewed SonyCrt.hpp header remains byte-identical to6b2c351, including both ELF hidden inline accessors. Current main’s qsort_s/bsearch_s qualifications remain alongside the time constraint debt. Older four-TZ/mutant/ASan module-isolation evidence keeps its original pins; it was not rerun here. Rebuilt actual libc/Ampr and selected tests from the final input tree. `guest_crt`, `guest_time_conversion`, `guest_mktime` each pass three consecutive runs: **9 runtime passes, zero skips**, plus public_headers. Conventions and whitespace pass. Source/input manifests, exact dependencies, library/test hashes, logs/JUnit and head-leased push receipts are attached. The same pinned main passes 18 selected groups three times (54 runtime passes) plus headers. All 34 recursive dependency trees/31,551 tracked blobs verify with zero errors; QuickJS’s update=none test262 corpus is explicitly excluded because it is not a library build input. Linux-7.2.11-arch1-1-x86_64-with-glibc2.44, Ryzen 9 7950X, GCC 16.2.1, Ninja Release, BUILD_TESTING=ON. Focused Linux CPU qualification only. Older Windows/module/reference reports retain their original pins; no fresh Windows/macOS, SDK-module, console, title/GPU or speed claim. AI-assisted: yes (Codex). Evidence: https://github.com/JJenkx/AnyPS5/releases/download/linux-validation-20261023/math-six-main-a4eca-linux-extra10321-20261102.tar.gz; SHA-256 525ccb31a5d3d0f5adced5fda58818d8432f06c0afa7290139adb60ae6664b54. Earlier dated qualifications below retain their recorded source/platform pins. Windows 11, WinLibs GCC 15.2.0 UCRT r7, Release, `main` `319621ba2e`. - **Native comparison:** a scratch loader calls the titles' functions by NID next to this build's, with the same recording handler installed on both sides. It compares the return value, the handler's calls and error, and the buffer bytes. The messages were recorded from the titles' handler, and `guest_crt` checks that this build passes the same ones. Results are the same with the `libc.prx` of PPSA07923 and of PPSA05916. | check | `main` | this PR | |---|---|---| | `asctime_s`, 20,000 random calls: sizes from 0 to above 2^62, null pointers, out-of-range fields | 17,930 differ | **0** | | `asctime_s`, 108 chosen cases: each size boundary, null pointers, each field limit, years | 80 differ | **0** | | `ctime_s`, 11 cases that fail before the time conversion | 11 differ | **0** | The titles' `ctime_s` calls an import the loader can't provide once it converts a valid time, so the `ctime_s` paths after `localtime_s`, including a failing `localtime_s`, are not compared. The debt entry now says that, instead of "the console's exact checks are not verified". - **Regression:** `guest_crt` checks each rule, the messages and the year padding. With the previous `SonyCrt.hpp` it fails (`LibcViolation("asctime_s: bad argument")`). - **Test set:** `guest_crt`, `guest_safe_errors`, `guest_bounds_checking`, `guest_qsort`, `guest_strftime`, `guest_mktime` and `guest_locale` pass 3/3. The same holds merged with #9935 (`7aa063d91c`) for `guest_crt`, `guest_safe_errors`, `guest_bounds_checking`, `guest_qsort` and `guest_strftime`. Conventions pass. <!-- codex-maintenance-20261029-repeat-12574 --> **Current Linux qualification and module-isolation correction — 2026-10-29** Addressed the review's test hardening and the Linux module-isolation bug it exposed in `6b2c35188f6706790c39f7ba302fc92148fbc7c6`. The added cases require destination-error precedence when the time pointer is also null, short-capacity rejection before converting an unrepresentable timestamp, and each time field's low−1/low/high/high+1 boundaries. The duplicated year assignment is removed. Each of the four proposed incorrect implementation variants now fails at its intended assertion. The exact original Linux `guest_crt` also revealed a real prerequisite issue: GNU_UNIQUE handler state coalesced across libc and Ampr, so installing Ampr's handler replaced libc's. The fix gives **both** internal inline state accessors (handler and mutex) ELF hidden visibility. They retain external inline linkage, sharing state across translation units inside one library while separating the libraries. Guest exports, NIDs and calling conventions are unchanged. The guard leaves PE/Mach-O visibility unchanged. No test counter resets were added to conceal unexpected callbacks. Qualification on Arch Linux7.2.9 / Ryzen9 7950X / GCC16.2.1 Release uses the actual libc/Ampr libraries: `guest_crt` passes three repetitions under each of UTC, America/New_York, Pacific/Kiritimati and TZ unset (12 passes). Four actual-header production mutants each fail the intended new assertion. Restoring the candidate passes the focused three-group set three times (9 checks) and restores identical libc and Ampr bytes. Public-header, conventions and whitespace checks pass. A separate ASan+UBSan harness builds the exact complete header into two DSOs, with two separately compiled translation units per DSO, and alternates setter/invoker translation units. It verifies sharing within each module, separation between modules and preservation of the sibling's handler across resets. The original header fails with “libc handler replaced by Ampr setter”; the fixed header passes. ELF symbol tables confirm the original state is UNIQUE/DEFAULT and fixed handler/mutex state is LOCAL. The full-runtime original failure and all expected negatives are preserved in the evidence. This module-state harness is separate from the actual-library CRT runs. No new Windows, macOS, title-library or physical-console measurement is claimed. Earlier Windows/title comparisons retain their original pins; the previously documented ctime paths after localtime conversion remain unmeasured. AI-assisted: yes (Codex). Evidence: [source, raw tests, original failure, sanitizer isolation proof and mutant/restoration receipts](https://github.com/JJenkx/AnyPS5/releases/download/linux-validation-20261023/libc-asctime-constraints-module-isolation-linux-20261029.tar.gz), SHA-256 `4f0d32cb26b6dfbce3e6c5750990844bc3970fd9b43c3aef2d901ed1050a4477`. ### Checklist - [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 (#9935 fulfilled through merged #10270; earlier agreed order retained as history) - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes (Claude Code)
rooklz commented 2026-10-28 21:25:30 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by rooklz on 2026-10-28T21:25:30Z.

Review: COMMENTED


Independent run on macOS arm64 (Apple clang, ASan+UBSan, -fno-sanitize-recover). The harness builds the PR's SonyCrt.hpp into two separate hidden-visibility dylibs, a libc side and an Ampr side, so each one keeps its own handler slot as in the real modules. localtime_s is a host localtime_r shim. The driver is the PR's guest_crt asctime/ctime block, lines 158-269.

  • Head e1dbfa0753: OK under TZ unset, UTC, America/New_York and Pacific/Kiritimati. No sanitizer reports.
  • main's SonyCrt.hpp with the head test: RED at LibcViolation("asctime_s: bad argument"), the failure your body describes.
  • Gates: conventions clean, git merge-tree against 319621ba2e clean. Merging with #9935 conflicts only on the set_constraint_handler_s debt line, as you said. pr_overlap also lists #9087, #9688, #10270 and #11621 on the same line, L81.

Mutants (20): the head test kills 14. Six survive:

mutant result
asctime_s checks !time before the destination check survives (the null time is only tested with a valid destination)
ctime_s drops size < 26 from the pre-conversion check and leaves it to SonyFormatAsctime survives (epoch converts, so the message and clearing are the same)
tm_sec > 61 survives
year < -1 survives
snprintf(buffer, size, ...) restored survives on macOS only. Darwin accepts sizes ≥ 2^32, so it behaves the same here; your 2^32 case should catch it on UCRT
ctime_s passes "asctime_s: bad argument" to SonyFormatAsctime survives. Only reachable with a year above 9999 after conversion, which you say wasn't compared, so I left it out

The test-only diff below kills the first four. With it, head stays green under all four TZ settings.

  • A null buffer with a null time, and size 0 with a null time, must both report the destination message.
  • ctime_s size 25 with an unconvertible time must still report ctime_s: bad argument before conversion.
  • Each field's limit is checked as low-1, low, high and high+1, which also pins tm_sec 60 and year 0/9999.

The diff also drops the duplicated known.tm_year = 70; line.

@@ -233,7 +233,6 @@ int main() {
     known.tm_year = 57 - 1900;
     Require(asctime_s_nid_postfix(text, sizeof(text), &known) == 0 && std::strcmp(text, "Thu Jan  1 00:00:00 0057\n") == 0);
     known.tm_year = 70;
-    known.tm_year = 70;
     known.tm_mday = 32;
     text[0] = 'x';
     Require(sceAmprAsctimeS(text, sizeof(text), &known) == EINVAL && text[0] == '\0');
@@ -263,6 +262,28 @@ int main() {
     Require(LibcViolation("ctime_s: bad argument"));
     std::memset(libcText, 'x', sizeof(libcText));
     Require(ctime_s_nid_postfix(libcText, std::size_t{1} << 32, &epoch) == 0 && std::strcmp(libcText, text) == 0 && libcText[26] == 'x');
+    Require(asctime_s_nid_postfix(nullptr, sizeof(text), nullptr) == EINVAL);
+    Require(LibcViolation("asctime_s: bad destination argument"));
+    text[0] = 'x';
+    Require(asctime_s_nid_postfix(text, 0, nullptr) == EINVAL && text[0] == 'x');
+    Require(LibcViolation("asctime_s: bad destination argument"));
+    const std::int64_t unconvertible = INT64_MAX;
+    libcText[0] = 'x';
+    Require(ctime_s_nid_postfix(libcText, 25, &unconvertible) == EINVAL && libcText[0] == '\0');
+    Require(LibcViolation("ctime_s: bad argument"));
+    struct FieldLimit { int GuestTm::*field; int low; int high; };
+    for (const FieldLimit limit : {FieldLimit{&GuestTm::tm_sec, 0, 60}, FieldLimit{&GuestTm::tm_min, 0, 59}, FieldLimit{&GuestTm::tm_hour, 0, 23},
+             FieldLimit{&GuestTm::tm_mday, 1, 31}, FieldLimit{&GuestTm::tm_mon, 0, 11}, FieldLimit{&GuestTm::tm_wday, 0, 6},
+             FieldLimit{&GuestTm::tm_yday, 0, 365}, FieldLimit{&GuestTm::tm_year, -1900, 9999 - 1900}}) {
+        for (const int value : {limit.low - 1, limit.low, limit.high, limit.high + 1}) {
+            GuestTm fields = known;
+            fields.*limit.field = value;
+            text[0] = 'x';
+            const bool valid = value >= limit.low && value <= limit.high;
+            Require(asctime_s_nid_postfix(text, sizeof(text), &fields) == (valid ? 0 : EINVAL));
+            Require(valid ? (g_libcConstraintCalls == 0 && std::strlen(text) == 25) : (text[0] == '\0' && LibcViolation("asctime_s: bad argument")));
+        }
+    }
     set_constraint_handler_s_nid_postfix(previousLibcHandler);
     Require(sceAmprCtimeS(text, 25, &epoch) == EINVAL);
     text[0] = 'x';
<!-- greyfinch-sync:boykopovar/AnyPS5:review:5689897635 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/12574#pullrequestreview-5689897635). Originally posted by [rooklz](https://github.com/rooklz) on 2026-10-28T21:25:30Z. **Review:** COMMENTED --- Independent run on **macOS arm64** (Apple clang, ASan+UBSan, `-fno-sanitize-recover`). The harness builds the PR's `SonyCrt.hpp` into two separate hidden-visibility dylibs, a libc side and an Ampr side, so each one keeps its own handler slot as in the real modules. `localtime_s` is a host `localtime_r` shim. The driver is the PR's `guest_crt` asctime/ctime block, lines 158-269. - Head `e1dbfa0753`: OK under TZ unset, UTC, America/New_York and Pacific/Kiritimati. No sanitizer reports. - `main`'s `SonyCrt.hpp` with the head test: RED at `LibcViolation("asctime_s: bad argument")`, the failure your body describes. - Gates: conventions clean, `git merge-tree` against `319621ba2e` clean. Merging with #9935 conflicts only on the `set_constraint_handler_s` debt line, as you said. pr_overlap also lists #9087, #9688, #10270 and #11621 on the same line, L81. **Mutants (20):** the head test kills 14. Six survive: | mutant | result | |---|---| | `asctime_s` checks `!time` before the destination check | survives (the null time is only tested with a valid destination) | | `ctime_s` drops `size < 26` from the pre-conversion check and leaves it to `SonyFormatAsctime` | survives (`epoch` converts, so the message and clearing are the same) | | `tm_sec > 61` | survives | | `year < -1` | survives | | `snprintf(buffer, size, ...)` restored | survives on macOS only. Darwin accepts sizes ≥ 2^32, so it behaves the same here; your 2^32 case should catch it on UCRT | | `ctime_s` passes `"asctime_s: bad argument"` to `SonyFormatAsctime` | survives. Only reachable with a year above 9999 after conversion, which you say wasn't compared, so I left it out | The test-only diff below kills the first four. With it, head stays green under all four TZ settings. - A null buffer with a null time, and size 0 with a null time, must both report the **destination** message. - `ctime_s` size 25 with an unconvertible time must still report `ctime_s: bad argument` before conversion. - Each field's limit is checked as low-1, low, high and high+1, which also pins `tm_sec` 60 and year 0/9999. The diff also drops the duplicated `known.tm_year = 70;` line. ```diff @@ -233,7 +233,6 @@ int main() { known.tm_year = 57 - 1900; Require(asctime_s_nid_postfix(text, sizeof(text), &known) == 0 && std::strcmp(text, "Thu Jan 1 00:00:00 0057\n") == 0); known.tm_year = 70; - known.tm_year = 70; known.tm_mday = 32; text[0] = 'x'; Require(sceAmprAsctimeS(text, sizeof(text), &known) == EINVAL && text[0] == '\0'); @@ -263,6 +262,28 @@ int main() { Require(LibcViolation("ctime_s: bad argument")); std::memset(libcText, 'x', sizeof(libcText)); Require(ctime_s_nid_postfix(libcText, std::size_t{1} << 32, &epoch) == 0 && std::strcmp(libcText, text) == 0 && libcText[26] == 'x'); + Require(asctime_s_nid_postfix(nullptr, sizeof(text), nullptr) == EINVAL); + Require(LibcViolation("asctime_s: bad destination argument")); + text[0] = 'x'; + Require(asctime_s_nid_postfix(text, 0, nullptr) == EINVAL && text[0] == 'x'); + Require(LibcViolation("asctime_s: bad destination argument")); + const std::int64_t unconvertible = INT64_MAX; + libcText[0] = 'x'; + Require(ctime_s_nid_postfix(libcText, 25, &unconvertible) == EINVAL && libcText[0] == '\0'); + Require(LibcViolation("ctime_s: bad argument")); + struct FieldLimit { int GuestTm::*field; int low; int high; }; + for (const FieldLimit limit : {FieldLimit{&GuestTm::tm_sec, 0, 60}, FieldLimit{&GuestTm::tm_min, 0, 59}, FieldLimit{&GuestTm::tm_hour, 0, 23}, + FieldLimit{&GuestTm::tm_mday, 1, 31}, FieldLimit{&GuestTm::tm_mon, 0, 11}, FieldLimit{&GuestTm::tm_wday, 0, 6}, + FieldLimit{&GuestTm::tm_yday, 0, 365}, FieldLimit{&GuestTm::tm_year, -1900, 9999 - 1900}}) { + for (const int value : {limit.low - 1, limit.low, limit.high, limit.high + 1}) { + GuestTm fields = known; + fields.*limit.field = value; + text[0] = 'x'; + const bool valid = value >= limit.low && value <= limit.high; + Require(asctime_s_nid_postfix(text, sizeof(text), &fields) == (valid ? 0 : EINVAL)); + Require(valid ? (g_libcConstraintCalls == 0 && std::strlen(text) == 25) : (text[0] == '\0' && LibcViolation("asctime_s: bad argument"))); + } + } set_constraint_handler_s_nid_postfix(previousLibcHandler); Require(sceAmprCtimeS(text, 25, &epoch) == EINVAL); text[0] = 'x'; ```
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!12574
No description provided.