fix(libSceRtc): check current tick before local time conversion #12535
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/12535"
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 LuPetro on 2026-10-28T18:33:15Z.
What
A process-local clock can be set beyond the representable calendar range.
sceRtcGetCurrentClockLocalTimepassed that tick into the host timezone conversion before the range check inaddTicks, which can throw and abort the guest on Windows. The corresponding UTC getter already returns0x80B50003for an out-of-range current tick.Check the current tick before timezone conversion and return the same error without writing the output. Console behavior for this extreme process-local clock state is unmeasured and is recorded in libSceRtc's technical debt.
Tested
libstarget built on the submitted head. Addedguest_rtccases for ticks immediately above the calendar limit, at 2^63, and at UINT64_MAX. With main's implementation the test aborted during timezone conversion; with the changeguest_rtcandguest_rtc_ps5_titlepassed.994049e8bf) changes the same test file;git merge-treeproduced a clean merge and both variants of the combined RTC test ran successfully on Windows.tools/check_test_registration.py --scripts build-libs-winlibspassed.tools/check_conventions.py --base HEAD^passed against the actual base319621ba2e; the required--base origin/maincheck encountered an unrelated historical non-conventional revert because the fork's main is stale.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 MarcZX10 on 2026-10-28T18:45:52Z.
Review: APPROVED
Reviewed — looks good
The new range check prevents local-time conversion from receiving an out-of-range current tick, and I found no blocking defect.
What I ran
Reviewed head
dab16d01a97ddcf5aff59452e30335cc694187adagainst base319621ba2e578bd053b0baba2877fe70520e0737; merge tree is clean. Environment: Debian 12 x86_64, GCC 12.2.0, QEMU user-mode x86_64. I initialized the pinned submodules in an isolated detached worktree.For the negative control, I temporarily removed the guard only in the isolated worktree, rebuilt, ran the test, restored the committed file, rebuilt, and reran the test:
Results
guest_rtc_testsbuildguest_rtcCTestguest_rtc_testsunder QEMU-cpu maxgit diff --checkmainmerged)libstarget built;guest_rtcandguest_rtc_ps5_titlepassed; author reports the main implementation aborted in the conversion pathCommand output
Negative control
0x80B50003without converting local timeFindings
Blocking
None found.
Non-blocking
The Linux negative control does not distinguish the guard because this host handles the tested conversion path differently. The Windows-specific behavior is supported by the author's reported Windows run; I did not independently reproduce it on Windows.
Sources
sceRtcGetCurrentClockLocalTimeat the reviewed headNot verified
I did not independently test Windows, a PS5 console, or the skipped Linux and specialized hosted jobs. The hosted Windows workflow passed; the PR description reports the focused Windows tests but not raw logs in this review.
Imported from boykopovar/AnyPS5. Originally posted by rooklz on 2026-10-28T20:28:16Z.
Review: APPROVED
I reproduced this from macOS against head
dab16d01a9(base319621ba2e).Windows-target repro (MinGW-w64 GCC from Homebrew, static, run under Wine). This is a standalone build of
libSceRtc/Export.cpp+tests/GuestRtc.cpp+ the libc process-parameter and AppMetadata sources it needs, with a one-symbolNotImplemented_nid_no_patchabort shim that the test never reaches.guest_rtcrc 0,guest_rtc ps5-titlerc 0Export.cppwith head's test: rc 3,terminate ... sceRtc: the host cannot convert this tick to local time. This is the abort your Tested section describes.macOS arm64, ASan+UBSan, same standalone set. Head passes in both modes. Base also passes because the Darwin
localtime_rconverts these ticks, but UBSan reportssigned integer overflow: -9223372036854775808 - 62135596800000000atlocalOffsetSeconds(Export.cpp:164). Head's new guard keepssceRtcGetCurrentClockLocalTimeaway from that line, and the head test run has 0 UBSan reports. So the change also removes UB on POSIX, but only a sanitizer build sees the regression there.Mutants. Removing the guard is caught on Windows (= base). On POSIX it shows up only as the UBSan report. Changing
>to>=survives. It can't really be tested: a current tick set to exactlyMAX_TICKhas already moved past it by the time the getter reads it.Other checks. Probing the sibling local-time entry points on Windows, head and base behave the same:
ConvertUtcToLocalTime,ConvertLocalTimeToUtc,FormatRFC3339LocalTimeandFormatRFC2822LocalTimealready range-check first and return0x80B50003at 2^63,MAX_TICK+1and UINT64_MAX.check_conventions --base upstream/mainpasses.git merge-treeis clean against main and against #12222.Follow-up, not this PR.
sceRtcFormatRFC3339PreciseLocalTimehas the same Windows abort on head and base. An explicit tick of0x0dcbffeb5b4a0000or 2^63, or a null tick with that current clock, reacheslocalOffsetMinutesbefore any range check.MAX_TICK+1and UINT64_MAX return0x80B50008as the debt entry says. The debt entry says this variant takes the offset at the tick and checks only the local result, so the same guard isn't a drop-in fix there. It needs its own change.Approving.