fix(libSceRtc): reject far-future ticks before precise local time conversion #12570

Merged
rooklz merged 1 commit from upstream-pr/12570 into main 2026-10-29 20:00:48 +00:00
rooklz commented 2026-10-28 20:46:45 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by rooklz on 2026-10-28T20:46:45Z.


What

sceRtcFormatRFC3339PreciseLocalTime asks the host for the local offset at the tick before checking the range. On Windows, a tick far past year 9999 (2^63, or 0x0dcbffeb5b4a0000) is out of range for localtime_s, even after the 400-year cycle retries. localOffsetSeconds then throws sceRtc: the host cannot convert this tick to local time and 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+1 in a zone west of UTC still formats as 9999-12-31T21:00:00.000-03:00, and why the MAX_TICK guard that #12535 adds to sceRtcGetCurrentClockLocalTime would be wrong here. This change rejects only ticks that no valid zone could bring back to 9999 or earlier: more than 1439 minutes past MAX_TICK. For those, sceRtcFormatRFC3339Precise returns 0x80B50008 for 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 returns 0x80B50003. Ticks between MAX_TICK and MAX_TICK + 1439 min go 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, TZ XXX+23:59): MAX_TICK + 1439 min still formats as 9999-12-31T23:59:59.999999-23:59. One tick later, 2^63 and UINT64_MAX return 0x80B50008 and leave the buffer untouched, and precision 7 at those ticks returns 0x80B50003.

Tested

macOS 26.2 (Apple M5), base 319621ba2e. guest_rtc is not part of the relinker-only build, so I built it standalone: libSceRtc/Export.cpp + tests/GuestRtc.cpp + libc/src/ApplicationProcessParameters.cpp + the AppMetadata sources, plus a shim that provides NotImplemented_nid_no_patch (abort) and ResolvePath_nid_no_patch (/app0/... → cwd).

  • Windows target (Homebrew MinGW-w64 GCC, -static, run under Wine):
    • this branch: guest_rtc rc 0, guest_rtc ps5-title rc 0
    • base Export.cpp with the new test: rc 3, terminate ... sceRtc: the host cannot convert this tick to local time
    • base Export.cpp with the base test: rc 0
  • macOS arm64, ASan+UBSan, clang:
    • this branch: both modes rc 0, 0 UBSan reports
    • base Export.cpp with the new test: rc 0, plus the UBSan signed-overflow report at Export.cpp:164
  • Mutants (Windows target): removing the check, >=, a 1438-minute window, INVALID_VALUE instead of INVALID_YEAR, moving the check before the precision check, and a plain > MAX_TICK check 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 returns 0x80B50008 for every zone.
  • Relinker-only Release build with 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-tree against #12535 is also clean (that PR touches the neighbouring debt line).

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:5057446982 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/12570). Originally posted by [rooklz](https://github.com/rooklz) on 2026-10-28T20:46:45Z. --- ### What `sceRtcFormatRFC3339PreciseLocalTime` asks the host for the local offset at the tick before checking the range. On Windows, a tick far past year 9999 (2^63, or `0x0dcbffeb5b4a0000`) is out of range for `localtime_s`, even after the 400-year cycle retries. `localOffsetSeconds` then throws `sceRtc: the host cannot convert this tick to local time` and 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+1` in a zone west of UTC still formats as `9999-12-31T21:00:00.000-03:00`, and why the `MAX_TICK` guard that #12535 adds to `sceRtcGetCurrentClockLocalTime` would be wrong here. This change rejects only ticks that no valid zone could bring back to 9999 or earlier: more than 1439 minutes past `MAX_TICK`. For those, `sceRtcFormatRFC3339Precise` returns `0x80B50008` for 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 returns `0x80B50003`. Ticks between `MAX_TICK` and `MAX_TICK + 1439 min` go 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`, TZ `XXX+23:59`): `MAX_TICK + 1439 min` still formats as `9999-12-31T23:59:59.999999-23:59`. One tick later, 2^63 and UINT64_MAX return `0x80B50008` and leave the buffer untouched, and precision 7 at those ticks returns `0x80B50003`. ### Tested macOS 26.2 (Apple M5), base `319621ba2e`. `guest_rtc` is not part of the relinker-only build, so I built it standalone: `libSceRtc/Export.cpp` + `tests/GuestRtc.cpp` + `libc/src/ApplicationProcessParameters.cpp` + the `AppMetadata` sources, plus a shim that provides `NotImplemented_nid_no_patch` (abort) and `ResolvePath_nid_no_patch` (`/app0/...` → cwd). - **Windows target** (Homebrew MinGW-w64 GCC, `-static`, run under Wine): - this branch: `guest_rtc` rc 0, `guest_rtc ps5-title` rc 0 - base `Export.cpp` with the new test: rc 3, `terminate ... sceRtc: the host cannot convert this tick to local time` - base `Export.cpp` with the base test: rc 0 - **macOS arm64, ASan+UBSan, clang:** - this branch: both modes rc 0, 0 UBSan reports - base `Export.cpp` with the new test: rc 0, plus the UBSan signed-overflow report at Export.cpp:164 - **Mutants** (Windows target): removing the check, `>=`, a 1438-minute window, `INVALID_VALUE` instead of `INVALID_YEAR`, moving the check before the precision check, and a plain `> MAX_TICK` check 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 returns `0x80B50008` for every zone. - Relinker-only Release build with `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-tree` against #12535 is also clean (that PR touches the neighbouring debt line). ### 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 - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
MarcZX10 commented 2026-10-28 20:54:27 +00:00 (Migrated from github.com)

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

  • PR head: 8f8bb6630dda09a2473006a20deef517931e20e5; current main: 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, tree 475ca116080ea4bbd68bc7cf660cc38d6694034d.
  • Pairwise merge previews with #12549 and #12535 are clean (24322b5e65b9c2ce115de1f57d144c21051cd526 and 671f57b271fd1055de063a97540e1ed5feface2d).
  • Read the exact implementation, regression assertions and updated debt text. I did not build or run the RTC tests locally.

Results

Check Result
Diff check Passed
Merge preview onto current main Clean
Pairwise merge preview with #12549 Clean
Pairwise merge preview with #12535 Clean
Hosted eligibility, conventions, intake, labels Passed
Hosted Windows job Passed
Hosted Linux and specialized jobs Skipped
Focused RTC tests Author reports Windows-target and macOS ASan/UBSan runs; not independently rerun here
Raw merge and diff-check output
$ git merge-tree --write-tree upstream/main refs/review/pr-12570-current
475ca116080ea4bbd68bc7cf660cc38d6694034d
$ git merge-tree --write-tree refs/review/pr-12549-current refs/review/pr-12570-current
24322b5e65b9c2ce115de1f57d144c21051cd526
$ git merge-tree --write-tree refs/review/pr-12535-current refs/review/pr-12570-current
671f57b271fd1055de063a97540e1ed5feface2d
$ git diff --check upstream/main...refs/review/pr-12570-current
(no output; exit 0)

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.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5689563668 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/12570#pullrequestreview-5689563668). Originally posted by [MarcZX10](https://github.com/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 - PR head: `8f8bb6630dda09a2473006a20deef517931e20e5`; current `main`: `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, tree `475ca116080ea4bbd68bc7cf660cc38d6694034d`. - Pairwise merge previews with #12549 and #12535 are clean (`24322b5e65b9c2ce115de1f57d144c21051cd526` and `671f57b271fd1055de063a97540e1ed5feface2d`). - Read the exact implementation, regression assertions and updated debt text. I did not build or run the RTC tests locally. ## Results | Check | Result | |---|---| | Diff check | Passed | | Merge preview onto current `main` | Clean | | Pairwise merge preview with #12549 | Clean | | Pairwise merge preview with #12535 | Clean | | Hosted eligibility, conventions, intake, labels | Passed | | Hosted Windows job | Passed | | Hosted Linux and specialized jobs | Skipped | | Focused RTC tests | Author reports Windows-target and macOS ASan/UBSan runs; not independently rerun here | <details> <summary>Raw merge and diff-check output</summary> ```text $ git merge-tree --write-tree upstream/main refs/review/pr-12570-current 475ca116080ea4bbd68bc7cf660cc38d6694034d $ git merge-tree --write-tree refs/review/pr-12549-current refs/review/pr-12570-current 24322b5e65b9c2ce115de1f57d144c21051cd526 $ git merge-tree --write-tree refs/review/pr-12535-current refs/review/pr-12570-current 671f57b271fd1055de063a97540e1ed5feface2d $ git diff --check upstream/main...refs/review/pr-12570-current (no output; exit 0) ``` </details> ## 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 - [Tick bound and error precedence at the reviewed head](https://github.com/boykopovar/AnyPS5/blob/8f8bb6630dda09a2473006a20deef517931e20e5/core/libs/prx/libSceRtc/Export.cpp#L780-L790) - [Boundary and untouched-buffer regression at the reviewed head](https://github.com/boykopovar/AnyPS5/blob/8f8bb6630dda09a2473006a20deef517931e20e5/core/libs/tests/GuestRtc.cpp#L902-L924) - [Contribution rules for overlapping changes and tests](https://github.com/boykopovar/AnyPS5/blob/319621ba2e578bd053b0baba2877fe70520e0737/CONTRIBUTING.md#L63-L70) ## 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.
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!12570
No description provided.