fix(libSceRtc): reject far-future ticks before precise local time conversion #12570
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/12570"
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 rooklz on 2026-10-28T20:46:45Z.
What
sceRtcFormatRFC3339PreciseLocalTimeasks the host for the local offset at the tick before checking the range. On Windows, a tick far past year 9999 (2^63, or0x0dcbffeb5b4a0000) is out of range forlocaltime_s, even after the 400-year cycle retries.localOffsetSecondsthen throwssceRtc: the host cannot convert this tick to local timeand the process terminates. A null tick goes through the same path when the current clock was set that far ahead. On POSIX the same call hits a signed overflow at Export.cpp:164 (-9223372036854775808 - 62135596800000000), which UBSan reports.The debt entry for this function records that the local-time variant takes the offset at the tick and checks only the local result. That is why
MAX_TICK+1in a zone west of UTC still formats as9999-12-31T21:00:00.000-03:00, and why theMAX_TICKguard that #12535 adds tosceRtcGetCurrentClockLocalTimewould be wrong here. This change rejects only ticks that no valid zone could bring back to 9999 or earlier: more than 1439 minutes pastMAX_TICK. For those,sceRtcFormatRFC3339Precisereturns0x80B50008for every zone in -1439..1439, so the new check returns that same result without reading the host time zone. The check runs after the precision check, so a bad precision still returns0x80B50003. Ticks betweenMAX_TICKandMAX_TICK + 1439 mingo through the existing path unchanged.The new debt line notes that the result for such ticks is derived from the measured local-result rule and was not measured on a console.
Test (in
GuestRtc.cpp, TZXXX+23:59):MAX_TICK + 1439 minstill formats as9999-12-31T23:59:59.999999-23:59. One tick later, 2^63 and UINT64_MAX return0x80B50008and leave the buffer untouched, and precision 7 at those ticks returns0x80B50003.Tested
macOS 26.2 (Apple M5), base
319621ba2e.guest_rtcis not part of the relinker-only build, so I built it standalone:libSceRtc/Export.cpp+tests/GuestRtc.cpp+libc/src/ApplicationProcessParameters.cpp+ theAppMetadatasources, plus a shim that providesNotImplemented_nid_no_patch(abort) andResolvePath_nid_no_patch(/app0/...→ cwd).-static, run under Wine):guest_rtcrc 0,guest_rtc ps5-titlerc 0Export.cppwith the new test: rc 3,terminate ... sceRtc: the host cannot convert this tick to local timeExport.cppwith the base test: rc 0Export.cppwith the new test: rc 0, plus the UBSan signed-overflow report at Export.cpp:164>=, a 1438-minute window,INVALID_VALUEinstead ofINVALID_YEAR, moving the check before the precision check, and a plain> MAX_TICKcheck are all killed. A 1440-minute window survives and is equivalent: the ticks it lets through fall within one minute past the 1439-minute bound, the host converts them, and the existing local-result check returns0x80B50008for every zone.BUILD_TESTING=ON: CTest 391/391 passed.check_conventions.py --base upstream/main: clean.pr_overlap.py --branch fix/rtc-precise-local-far-tick: 1371 PRs probed, no overlap.git merge-treeagainst #12535 is also clean (that PR touches the neighbouring debt line).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-28T20:54:27Z.
Review: APPROVED
Reviewed — looks good
The guard rejects only ticks that no permitted timezone offset can bring within year 9999, while preserving the tested west-of-UTC boundary and precision-error precedence.
What I ran
8f8bb6630dda09a2473006a20deef517931e20e5; currentmain:319621ba2e578bd053b0baba2877fe70520e0737.git diff --check upstream/main...refs/review/pr-12570-current— passed (no output).git merge-tree --write-tree upstream/main refs/review/pr-12570-current— clean, tree475ca116080ea4bbd68bc7cf660cc38d6694034d.24322b5e65b9c2ce115de1f57d144c21051cd526and671f57b271fd1055de063a97540e1ed5feface2d).Results
mainRaw merge and diff-check output
Negative control
Not run locally. The PR description reports that the base implementation with the new regression terminates on the Windows target with the host conversion error and triggers signed-overflow UBSan on macOS arm64.
Findings
Blocking
None found in the reviewed change.
Non-blocking
The focused platform runs and negative controls are author-provided evidence. I did not independently reproduce them; the hosted Windows job passed, while hosted Linux and specialized jobs were skipped.
Sources
Not verified
I did not run the focused test, the full CTest suite, console behavior, or an independent platform run. The PR author reports macOS arm64 ASan/UBSan and Windows-target runs; hosted Windows CI passed.
To get this to a good state
No code change is needed based on this review. If the head changes, I will recheck the boundary and error-precedence assertions on the new head.