fix(libc): check asctime_s and ctime_s arguments as titles' libc.prx does #12574
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/12574"
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 JJenkx on 2026-10-28T21:08:31Z.
Current-main integration — 2026-11-12. Head
079738c3f9merges mainc85dcfd005(063c638608) and adds one test commit.SonyCrt.hpp: main's out-of-line handler declarations are taken unchanged.docs/dev/debt/libc.md: this PR'sasctime_s/ctime_swording is kept, and the per-module handler sentence that main removed stays removed.sceAmprAsctimeSviolation made whileguest_crt's recording handler is installed now reaches that handler too. With the merge alone,guest_crtfailed at line 230 in 3 of 3 runs. The new commit checks each of those seven calls with its own message.guest_crt,guest_time_conversion,guest_mktimeandguest_time_extraspass in 3 of 3 runs.check_conventions.pypasses.Current-main integration — 2026-11-05. Exact head
b5644e160f5596522221f2df822a511fd4fe9e12retains previous public25ab50c9e70bdaced8575d715ae4422faf8de704and tested main6d173c1a19788ff69d43b3d0ca62833e312ef939as 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 forSonyCrt.hpppass.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 head545e24b2ee2e549001421f7fc9f87ff801f3423c. 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::createSampleShadowallocation 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 main7ad9749ed0311cc91d69bc7c690d09c92b9d42d0is clean; qualification remains pinned to6d173c1a19788ff69d43b3d0ca62833e312ef939.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_sandctime_s(libc, and libSceAmpr through the shared header) now check their arguments the way thelibc.prxthat titles ship does. Every violation calls the constraint handler withEINVAL, as the other_sfunctions in this module already do. Onmainthese two returnedEINVALwithout calling it.Measured rules, applied in this order (the handler's pointer argument is always null):
sizeof 0, or asizeaboveSIZE_MAX >> 3(from 2^61): message"asctime_s: bad destination argument"(orctime_s), and nothing is written.sizeunder 26, a null time, or a field out of range: message"asctime_s: bad argument", and'\0'is stored in the first byte.ctime_schecks the size before it converts the time.The field limits were already right, except that
tm_ydayoutside 0 to 365 is now rejected too. Two output fixes:0957), as plainasctimealready does.sizeof 2^32 up,mainreturned 0 without writing anything, becausesnprintfrejected 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.prxin #8711, which they closed on 2026-10-21 after it needed a rebase. That PR also coveredstrtok_sand_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,EINVALwith 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
3728cf4c67moved the Sony CRT handler state intoSonyCrt.cppand 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
25ab50c9e70bdaced8575d715ae4422faf8de704merges main9ab6a281ea61c9e62a7eb07eb4cef8f19ede1c5cwhile 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_mktimeeach 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
cec91f3fe5e8f335b89b5dfd6ef16bdf073edbd6includes mainb11c7bf84f5d2f636ff60166cc3371bd071e24d5and 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_mktimeeach 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
af6f89bff19ee5d6d7f782db2163406a49a28327includes pinned maina4eca2a056bf3bbbec98ab42e9d28163e4ea9cb8. 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_mktimeeach 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,
main319621ba2e.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_crtchecks that this build passes the same ones. Results are the same with thelibc.prxof PPSA07923 and of PPSA05916.mainasctime_s, 20,000 random calls: sizes from 0 to above 2^62, null pointers, out-of-range fieldsasctime_s, 108 chosen cases: each size boundary, null pointers, each field limit, yearsctime_s, 11 cases that fail before the time conversionThe titles'
ctime_scalls an import the loader can't provide once it converts a valid time, so thectime_spaths afterlocaltime_s, including a failinglocaltime_s, are not compared. The debt entry now says that, instead of "the console's exact checks are not verified".Regression:
guest_crtchecks each rule, the messages and the year padding. With the previousSonyCrt.hppit fails (LibcViolation("asctime_s: bad argument")).Test set:
guest_crt,guest_safe_errors,guest_bounds_checking,guest_qsort,guest_strftime,guest_mktimeandguest_localepass 3/3. The same holds merged with #9935 (7aa063d91c) forguest_crt,guest_safe_errors,guest_bounds_checking,guest_qsortandguest_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_crtalso 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_crtpasses 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
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)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'sSonyCrt.hppinto 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_sis a hostlocaltime_rshim. The driver is the PR'sguest_crtasctime/ctime block, lines 158-269.e1dbfa0753: OK under TZ unset, UTC, America/New_York and Pacific/Kiritimati. No sanitizer reports.main'sSonyCrt.hppwith the head test: RED atLibcViolation("asctime_s: bad argument"), the failure your body describes.git merge-treeagainst319621ba2eclean. Merging with #9935 conflicts only on theset_constraint_handler_sdebt 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:
asctime_schecks!timebefore the destination checkctime_sdropssize < 26from the pre-conversion check and leaves it toSonyFormatAsctimeepochconverts, so the message and clearing are the same)tm_sec > 61year < -1snprintf(buffer, size, ...)restoredctime_spasses"asctime_s: bad argument"toSonyFormatAsctimeThe test-only diff below kills the first four. With it, head stays green under all four TZ settings.
ctime_ssize 25 with an unconvertible time must still reportctime_s: bad argumentbefore conversion.tm_sec60 and year 0/9999.The diff also drops the duplicated
known.tm_year = 70;line.