libRtc: implement sceRtcFormatRFC2822 and the local-time formatters #1184

Open
github-bot wants to merge 3 commits from github-bot/gh-1184 into main AGit
Owner

@⁠overlordxrz-source on GitHub · 2026-10-08 02:31 UTC · original
overlordxrz-source:libs/rtc-rfc2822 → main · +298 −18 · 3 files · 3 commits · open

sceRtcFormatRFC2822 (eiuobaF-hK4), sceRtcFormatRFC2822LocalTime (AxHBk3eat04) and sceRtcFormatRFC3339LocalTime (DwuHIlLGW8I) are not registered. A game that calls one of them gets the unresolved-import stub, which returns 0 and leaves the caller's buffer untouched. The game then reads whatever bytes were already in that buffer as a date string.

This adds all three next to the existing sceRtcFormatRFC3339:

  • the step that turns a tick plus a time zone offset into calendar fields moves out of RtcFormatRFC3339 into a small helper, and both formatters use it
  • sceRtcFormatRFC2822 writes Wed, 07 Oct 2026 21:43:05 -0400, which is 31 characters plus the terminator. It stays inside the same 32-byte bound sceRtcFormatRFC3339 already uses.
  • the LocalTime variants use a zero offset. RtcConvertUtcToLocalTime deliberately keeps RTC local time equal to UTC, and these follow it, so the string still names the right instant.
  • errors: RTC_ERROR_INVALID_POINTER for a null buffer. A null tick formats the current time. An offset that moves the tick outside 0001..9999, or that would wrap it, returns RTC_ERROR_INVALID_VALUE without writing.
  • the RFC 3339 zone suffix now negates the offset in 64 bits, so an offset of INT_MIN is no longer undefined behaviour

Evidence

  • #908 Teenage Mutant Ninja Turtles: Splintered Fate (PPSA25582): Unresolved import stub called [0]: ... symbol=AxHBk3eat04[Rtc_v1][Rtc_v1.1][Func] ... eboot.bin, logged twice in a row
  • I didn't find sceRtcFormatRFC2822 or sceRtcFormatRFC3339LocalTime in the issue logs I have. I added them because they share the code with the one the game calls, and each is one line in InitRtc_1. I can drop them if you'd rather keep this to the one that's called.

I'm not claiming this changes how far TMNT gets. It only means the game gets a real date string.

Testing

New tests/RtcFormatTests.cpp (rtc_format_tests, added to kyty_tests and ctest). It includes libRtc.cpp the way CesTests.cpp includes libCes.cpp, then resolves the four formatters by NID through InitRtc_1. It checks:

  • RFC 2822 output for offsets 0, -240, +330, -570 and -1, a Sunday, 0001-01-01 and 9999-12-31 23:59:59
  • RFC 3339 output for 0, -240 and +345, and that the LocalTime variants match offset 0
  • null buffer and out-of-range or wrapping offsets give the right error and leave the buffer untouched
  • a null tick gives a 31-character current date
  • nothing is written past 32 bytes

What I ran (my machine is aarch64 Linux, no Vulkan):

  • built the test natively (zig c++ 0.16, static musl, with src/common/dateTime.cpp and stubs for DbgExit): all checks pass, including under -fsanitize=undefined. Against the old libRtc.cpp it fails on the three missing NIDs.
  • compiled libRtc.cpp and the test for x86_64-linux-gnu at -Wall -Wextra. The changed lines add no warnings.
  • changed lines are clean under src/.clang-format (clang-format 23.1.3)

I didn't run the CMake target itself, and I didn't build on Windows or macOS.

AI assistance

An AI assistant helped me find the missing export in the issue logs, write the change and the test, and run the builds above. I reviewed the code and the results.

**@⁠overlordxrz-source** on GitHub · 2026-10-08 02:31 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1184) `overlordxrz-source:libs/rtc-rfc2822` → `main` · +298 −18 · 3 files · 3 commits · open `sceRtcFormatRFC2822` (`eiuobaF-hK4`), `sceRtcFormatRFC2822LocalTime` (`AxHBk3eat04`) and `sceRtcFormatRFC3339LocalTime` (`DwuHIlLGW8I`) are not registered. A game that calls one of them gets the unresolved-import stub, which returns 0 and leaves the caller's buffer untouched. The game then reads whatever bytes were already in that buffer as a date string. This adds all three next to the existing `sceRtcFormatRFC3339`: - the step that turns a tick plus a time zone offset into calendar fields moves out of `RtcFormatRFC3339` into a small helper, and both formatters use it - `sceRtcFormatRFC2822` writes `Wed, 07 Oct 2026 21:43:05 -0400`, which is 31 characters plus the terminator. It stays inside the same 32-byte bound `sceRtcFormatRFC3339` already uses. - the `LocalTime` variants use a zero offset. `RtcConvertUtcToLocalTime` deliberately keeps RTC local time equal to UTC, and these follow it, so the string still names the right instant. - errors: `RTC_ERROR_INVALID_POINTER` for a null buffer. A null tick formats the current time. An offset that moves the tick outside 0001..9999, or that would wrap it, returns `RTC_ERROR_INVALID_VALUE` without writing. - the RFC 3339 zone suffix now negates the offset in 64 bits, so an offset of `INT_MIN` is no longer undefined behaviour ## Evidence - #908 Teenage Mutant Ninja Turtles: Splintered Fate (PPSA25582): `Unresolved import stub called [0]: ... symbol=AxHBk3eat04[Rtc_v1][Rtc_v1.1][Func] ... eboot.bin`, logged twice in a row - I didn't find `sceRtcFormatRFC2822` or `sceRtcFormatRFC3339LocalTime` in the issue logs I have. I added them because they share the code with the one the game calls, and each is one line in `InitRtc_1`. I can drop them if you'd rather keep this to the one that's called. I'm not claiming this changes how far TMNT gets. It only means the game gets a real date string. ## Testing New `tests/RtcFormatTests.cpp` (`rtc_format_tests`, added to `kyty_tests` and ctest). It includes `libRtc.cpp` the way `CesTests.cpp` includes `libCes.cpp`, then resolves the four formatters by NID through `InitRtc_1`. It checks: - RFC 2822 output for offsets 0, -240, +330, -570 and -1, a Sunday, `0001-01-01` and `9999-12-31 23:59:59` - RFC 3339 output for 0, -240 and +345, and that the `LocalTime` variants match offset 0 - null buffer and out-of-range or wrapping offsets give the right error and leave the buffer untouched - a null tick gives a 31-character current date - nothing is written past 32 bytes What I ran (my machine is aarch64 Linux, no Vulkan): - built the test natively (zig c++ 0.16, static musl, with `src/common/dateTime.cpp` and stubs for `DbgExit`): all checks pass, including under `-fsanitize=undefined`. Against the old `libRtc.cpp` it fails on the three missing NIDs. - compiled `libRtc.cpp` and the test for `x86_64-linux-gnu` at `-Wall -Wextra`. The changed lines add no warnings. - changed lines are clean under `src/.clang-format` (clang-format 23.1.3) I didn't run the CMake target itself, and I didn't build on Windows or macOS. ## AI assistance An AI assistant helped me find the missing export in the issue logs, write the change and the test, and run the builds above. I reviewed the code and the results.
sceRtcFormatRFC2822, sceRtcFormatRFC2822LocalTime and
sceRtcFormatRFC3339LocalTime were not registered. A game that calls one
of them hits the unresolved-import stub, which returns 0 and leaves the
caller's buffer untouched, so the game goes on to use whatever bytes
were already there as a date string. Teenage Mutant Ninja Turtles:
Splintered Fate (#908) calls sceRtcFormatRFC2822LocalTime twice in the
log attached to the issue.

The tick-to-calendar step that sceRtcFormatRFC3339 already did moves
into a shared helper. sceRtcFormatRFC2822 uses it and writes
"Wed, 07 Oct 2026 21:43:05 -0400": a 31-character date plus the
terminator, inside the same 32-byte bound sceRtcFormatRFC3339 uses.
A null buffer returns RTC_ERROR_INVALID_POINTER, a null tick formats
the current time, and an offset that moves the tick outside
0001..9999 returns RTC_ERROR_INVALID_VALUE without writing. The helper
now also rejects a positive offset that would wrap the tick, and the
RFC 3339 zone suffix negates the offset in 64 bits so INT_MIN is not
undefined behaviour.

The local-time variants use a zero offset. RtcConvertUtcToLocalTime
deliberately keeps RTC local time equal to UTC, and the formatters
follow it, so the string they produce still names the right instant.

tests/RtcFormatTests.cpp resolves the four formatters by NID through
InitRtc_1 and checks the output for several offsets, the first and
last representable days, the error codes and that nothing is written
past 32 bytes.
sceRtcFormatRFC2822 printed straight into the guest buffer with
snprintf(date_time, 32, ...) and returned OK whatever snprintf
returned. time_zone_minutes is not range-checked, so an offset of 6000
gives the zone "+10000" and a 32-character date: the guest got a
truncated string and OK. sceRtcFormatRFC3339 had the same unchecked
call, and its zone suffix was also truncated silently once the offset
reached 1000 hours.

Both formatters now build the string in a local 32-byte buffer, check
the snprintf result, and copy it to the guest only when it fits. A
string that does not fit, or a zone suffix that does not fit its own
buffer, returns RTC_ERROR_INVALID_VALUE and writes nothing. The
LocalTime variants go through the same code. Output for offsets that
fit is unchanged.

The tests cover the longest offsets that still fit (+-9959 for RFC 2822,
+999:59 for RFC 3339) and the first ones that do not, which must return
RTC_ERROR_INVALID_VALUE and leave the buffer untouched.
RFC 3339 allows only 00-23 for the offset hours, so sceRtcFormatRFC3339 and its LocalTime variant now return RTC_ERROR_INVALID_VALUE for an offset of 24 hours or more and leave the buffer untouched. The tests cover +/-23:59 and reject +/-24:00.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:46:54 +00:00
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-08 02:35 UTC · original · edited 2026-10-08 15:44 UTC

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository: KytyPS5/KytyPS5/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: f7645420-d3f7-4262-b644-f637efa279c5
📥 Commits

Reviewing files that changed from the base of the PR and between 810593da94 and 4d22fc111f.

📒 Files selected for processing (2)
  • src/libs/libRtc.cpp
  • tests/RtcFormatTests.cpp
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/libs/libRtc.cpp
  • tests/RtcFormatTests.cpp

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.


📝 Walkthrough

Walkthrough

RTC date-time formatting now applies time-zone offsets with underflow and overflow checks. RFC 2822 and local-time formatters are added and registered. A new test executable checks formatter output, return codes, and buffer boundaries. CMake builds and registers the test.

Priority: ⬇️ Low

Change: Bug fix

Merge Risk: ⚪ Minimal · up to 4d22f

The checked formatter and test-integration concerns do not block merging.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 23.53% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 17 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the main change: implementing RFC 2822 and local-time RTC formatters. It is concise and related to the changeset.
Description check ✅ Passed The description directly explains the missing registrations, formatter behavior, error handling, tests, and validation results.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

**@⁠coderabbitai[bot]** on GitHub · 2026-10-08 02:35 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1184#issuecomment-6051006004) · edited 2026-10-08 15:44 UTC <!-- This is an auto-generated comment: summarize by coderabbit.ai --> <!-- review_stack_entry_start --> <a href="https://app.coderabbit.ai/change-stack/KytyPS5/KytyPS5/pull/1184?scope=ghh_OusAJGA4HG8ljoOV0wJvVx8NmnZIjc2DdjmxOu0xZWA&amp;cs_source=review_comment"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui-dark.svg?v=2" alt="Review in Change Stack →" width="220" height="32"></a> <!-- review_stack_entry_end --> <!-- recent_review_start --> No actionable comments were generated in the recent review. 🎉 <details> <summary>ℹ️ Recent review info</summary> <details> <summary>⚙️ Run configuration</summary> - **Configuration used**: Repository: KytyPS5/KytyPS5/.coderabbit.yaml - **Review profile**: CHILL - **Plan**: Advanced - **Run ID**: `f7645420-d3f7-4262-b644-f637efa279c5` </details> <details> <summary>📥 Commits</summary> Reviewing files that changed from the base of the PR and between 810593da94ae1528410c9fd8da14dfc4c7d46c0e and 4d22fc111f381155065b4a135f81dccbcf988124. </details> <details> <summary>📒 Files selected for processing (2)</summary> * `src/libs/libRtc.cpp` * `tests/RtcFormatTests.cpp` </details> <details> <summary>🚧 Files skipped from review as they are similar to previous changes (2)</summary> * src/libs/libRtc.cpp * tests/RtcFormatTests.cpp </details> **Included review availability:** This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review. </details> --- <!-- recent_review_end --> <!-- walkthrough_start --> <details> <summary>📝 Walkthrough</summary> ## Walkthrough RTC date-time formatting now applies time-zone offsets with underflow and overflow checks. RFC 2822 and local-time formatters are added and registered. A new test executable checks formatter output, return codes, and buffer boundaries. CMake builds and registers the test. </details> <!-- walkthrough_end --> <!-- change_assessment_start --> **Priority:** ⬇️ Low <!-- change_assessment_commit:"4d22fc111f381155065b4a135f81dccbcf988124" --> **Change:** Bug fix <!-- change_assessment_end --> <!-- final_review_risk_start --> **Merge Risk:** **⚪ Minimal** · up to `4d22f` <!-- final_review_risk_coverage:{"sourceCommitId":"4d22fc111f381155065b4a135f81dccbcf988124","coveredCommitId":"4d22fc111f381155065b4a135f81dccbcf988124","kind":"reviewed"} --> The checked formatter and test-integration concerns do not block merging. <!-- final_review_risk_end --> <!-- pre_merge_checks_walkthrough_start --> <details> <summary>🚥 Pre-merge checks | ✅ 4 | ❌ 1</summary> ### ❌ Failed checks (1 warning) | Check name | Status | Explanation | Resolution | | :---------------- | :--------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | :--------------------------------------------------------------------------------- | | Docstring Coverage | ⚠️ Warning | Docstring coverage is 23.53% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 17 functions across 2 files. | Write docstrings for the functions missing them to satisfy the coverage threshold. | <details> <summary>✅ Passed checks (4 passed)</summary> | Check name | Status | Explanation | | :------------------------ | :------- | :--------------------------------------------------------------------------------------------------------------------------------------------- | | Title check | ✅ Passed | The title clearly identifies the main change: implementing RFC 2822 and local-time RTC formatters. It is concise and related to the changeset. | | Description check | ✅ Passed | The description directly explains the missing registrations, formatter behavior, error handling, tests, and validation results. | | Linked Issues check | ✅ Passed | Check skipped because no linked issues were found for this pull request. | | Out of Scope Changes check | ✅ Passed | Check skipped because no linked issues were found for this pull request. | </details> </details> <!-- pre_merge_checks_walkthrough_end --> <!-- autopilot:start --> - [ ] <!-- {"checkboxId":"2708ad07-9f24-4260-9c11-7dc76a49f2e3"} --> <strong title="Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts">Autopilot</strong> · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts <!-- autopilot:end --> <!-- tips_start --> --- Thanks for using [CodeRabbit](https://coderabbit.ai?utm_source=oss&utm_medium=github&utm_campaign=KytyPS5/KytyPS5&utm_content=1184)! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. <details> <summary>❤️ Share</summary> - [X](https://twitter.com/intent/tweet?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A&url=https%3A//coderabbit.ai) - [Mastodon](https://mastodon.social/share?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A%20https%3A%2F%2Fcoderabbit.ai) - [Reddit](https://www.reddit.com/submit?title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&text=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code.%20Check%20it%20out%3A%20https%3A//coderabbit.ai) - [LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fcoderabbit.ai&mini=true&title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&summary=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code) </details> <sub>Comment `@coderabbitai help` to get the list of available commands.</sub> <!-- tips_end -->
@ -355,2 +443,4 @@
return RtcFormatRFC2822(date_time, utc, RTC_LOCAL_TIME_ZONE_MINUTES);
}
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-08 02:35 UTC · original · edited 2026-10-08 02:49 UTC

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

🔎 Supported by static analysis

🏁 Script executed:

rg -n 'FormatRFC2822|time_zone_minutes|TIME_ZONE|TIMEZONE' src/libs/libRtc.cpp src tests/RtcFormatTests.cpp | head -110
sed -n '308,345p' src/libs/libRtc.cpp
sed -n '390,430p' src/libs/libRtc.cpp

Repository: KytyPS5/KytyPS5

Length of output: 7846


🏁 Script executed:

set -o pipefail
printf '%s\n' '--- declarations, registrations, callers, tests ---'
rg -n -F --glob '*.{h,hpp,cpp,c,cc}' -- 'RtcFormatRFC2822' . || test "$?" -eq 1
rg -n -F --glob '*.{h,hpp,cpp,c,cc}' -- 'eiuobaF-hK4' . || test "$?" -eq 1
rg -n -F --glob '*.{h,hpp,cpp,c,cc}' -- 'sceRtcFormatRFC2822' . || test "$?" -eq 1
printf '%s\n' '--- complete formatter/helper blocks ---'
nl -ba src/libs/libRtc.cpp | sed -n '300,430p'
printf '%s\n' '--- RTC test block ---'
nl -ba tests/RtcFormatTests.cpp | sed -n '120,190p'
printf '%s\n' '--- relevant exported API/type context ---'
nl -ba src/libs/libRtc.cpp | sed -n '1,90p'

Repository: KytyPS5/KytyPS5

Length of output: 11579


🏁 Script executed:

printf '%s\n' '--- exact references ---'
rg -n -F -- 'RtcFormatRFC2822' . || test "$?" -eq 1
rg -n -F -- 'eiuobaF-hK4' . || test "$?" -eq 1
rg -n -F -- 'sceRtcFormatRFC2822' . || test "$?" -eq 1
printf '%s\n' '--- implementation ---'
nl -ba src/libs/libRtc.cpp | sed -n '300,430p'
printf '%s\n' '--- tests ---'
nl -ba tests/RtcFormatTests.cpp | sed -n '120,190p'

Repository: KytyPS5/KytyPS5

Length of output: 8410


Check the RFC2822 formatted length before returning OK.

The exported formatter accepts time_zone_minutes as an int, and no range check rejects 6000. For a normal date, GetFormatDateTime adds 360000000000 ticks and succeeds. The format then needs 32 characters because 6000 minutes produces +10000. A 32-byte buffer holds only 31 characters plus the terminator, so snprintf truncates the result while the function returns OK.

Suggested fix
-	std::snprintf(date_time, 32, "%s, %02u %s %04u %02u:%02u:%02u %c%02d%02d", WEEK_DAYS[dow],
-	              static_cast<unsigned>(time.day), MONTHS[time.month - 1],
-	              static_cast<unsigned>(time.year), static_cast<unsigned>(time.hour),
-	              static_cast<unsigned>(time.minute), static_cast<unsigned>(time.second), sign,
-	              static_cast<int>(minutes / 60), static_cast<int>(minutes % 60));
+	const auto formatted =
+	    std::snprintf(date_time, 32, "%s, %02u %s %04u %02u:%02u:%02u %c%02d%02d", WEEK_DAYS[dow],
+	                  static_cast<unsigned>(time.day), MONTHS[time.month - 1],
+	                  static_cast<unsigned>(time.year), static_cast<unsigned>(time.hour),
+	                  static_cast<unsigned>(time.minute), static_cast<unsigned>(time.second), sign,
+	                  static_cast<int>(minutes / 60), static_cast<int>(minutes % 60));
+	if (formatted < 0 || formatted >= 32) {
+		return RTC_ERROR_INVALID_VALUE;
+	}

✅ Confirmed as addressed by @⁠overlordxrz-source

**@⁠coderabbitai[bot]** on GitHub · 2026-10-08 02:35 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1184#discussion_r4214028021) · edited 2026-10-08 02:49 UTC **🎯 Functional Correctness** | **🟡 Minor** | **⚡ Quick win** <details> <summary>🔎 Supported by static analysis</summary> 🏁 Script executed: ```bash rg -n 'FormatRFC2822|time_zone_minutes|TIME_ZONE|TIMEZONE' src/libs/libRtc.cpp src tests/RtcFormatTests.cpp | head -110 sed -n '308,345p' src/libs/libRtc.cpp sed -n '390,430p' src/libs/libRtc.cpp ``` Repository: KytyPS5/KytyPS5 Length of output: 7846 --- 🏁 Script executed: ```bash set -o pipefail printf '%s\n' '--- declarations, registrations, callers, tests ---' rg -n -F --glob '*.{h,hpp,cpp,c,cc}' -- 'RtcFormatRFC2822' . || test "$?" -eq 1 rg -n -F --glob '*.{h,hpp,cpp,c,cc}' -- 'eiuobaF-hK4' . || test "$?" -eq 1 rg -n -F --glob '*.{h,hpp,cpp,c,cc}' -- 'sceRtcFormatRFC2822' . || test "$?" -eq 1 printf '%s\n' '--- complete formatter/helper blocks ---' nl -ba src/libs/libRtc.cpp | sed -n '300,430p' printf '%s\n' '--- RTC test block ---' nl -ba tests/RtcFormatTests.cpp | sed -n '120,190p' printf '%s\n' '--- relevant exported API/type context ---' nl -ba src/libs/libRtc.cpp | sed -n '1,90p' ``` Repository: KytyPS5/KytyPS5 Length of output: 11579 --- 🏁 Script executed: ```bash printf '%s\n' '--- exact references ---' rg -n -F -- 'RtcFormatRFC2822' . || test "$?" -eq 1 rg -n -F -- 'eiuobaF-hK4' . || test "$?" -eq 1 rg -n -F -- 'sceRtcFormatRFC2822' . || test "$?" -eq 1 printf '%s\n' '--- implementation ---' nl -ba src/libs/libRtc.cpp | sed -n '300,430p' printf '%s\n' '--- tests ---' nl -ba tests/RtcFormatTests.cpp | sed -n '120,190p' ``` Repository: KytyPS5/KytyPS5 Length of output: 8410 --- </details> **Check the RFC2822 formatted length before returning `OK`.** The exported formatter accepts `time_zone_minutes` as an `int`, and no range check rejects `6000`. For a normal date, `GetFormatDateTime` adds `360000000000` ticks and succeeds. The format then needs 32 characters because `6000` minutes produces `+10000`. A 32-byte buffer holds only 31 characters plus the terminator, so `snprintf` truncates the result while the function returns `OK`. <details> <summary>Suggested fix</summary> ```diff - std::snprintf(date_time, 32, "%s, %02u %s %04u %02u:%02u:%02u %c%02d%02d", WEEK_DAYS[dow], - static_cast<unsigned>(time.day), MONTHS[time.month - 1], - static_cast<unsigned>(time.year), static_cast<unsigned>(time.hour), - static_cast<unsigned>(time.minute), static_cast<unsigned>(time.second), sign, - static_cast<int>(minutes / 60), static_cast<int>(minutes % 60)); + const auto formatted = + std::snprintf(date_time, 32, "%s, %02u %s %04u %02u:%02u:%02u %c%02d%02d", WEEK_DAYS[dow], + static_cast<unsigned>(time.day), MONTHS[time.month - 1], + static_cast<unsigned>(time.year), static_cast<unsigned>(time.hour), + static_cast<unsigned>(time.minute), static_cast<unsigned>(time.second), sign, + static_cast<int>(minutes / 60), static_cast<int>(minutes % 60)); + if (formatted < 0 || formatted >= 32) { + return RTC_ERROR_INVALID_VALUE; + } ``` </details> <!-- fingerprinting:phantom:medusa:wombat --> <!-- cr-indicator-types:potential_issue --> <!-- cr-comment:v1:314eef021678c1f76a3e971b --> <!-- This is an auto-generated reply by CodeRabbit --> ✅ Confirmed as addressed by @⁠overlordxrz-source <!-- This is an auto-generated comment by CodeRabbit -->
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-08 02:35 UTC · original · reviewed

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository: KytyPS5/KytyPS5/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: fe85f7a9-655a-4c34-924a-5ee8f4b87b9d
📥 Commits

Reviewing files that changed from the base of the PR and between 5a8808086a and 07b1b7f1d6.

📒 Files selected for processing (3)
  • CMakeLists.txt
  • src/libs/libRtc.cpp
  • tests/RtcFormatTests.cpp

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 6 remain after this review.

**@⁠coderabbitai[bot]** on GitHub · 2026-10-08 02:35 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1184#pullrequestreview-5450721124) · **reviewed** **Actionable comments posted: 1** --- <details> <summary>ℹ️ Review info</summary> <details> <summary>⚙️ Run configuration</summary> - **Configuration used**: Repository: KytyPS5/KytyPS5/.coderabbit.yaml - **Review profile**: CHILL - **Plan**: Advanced - **Run ID**: `fe85f7a9-655a-4c34-924a-5ee8f4b87b9d` </details> <details> <summary>📥 Commits</summary> Reviewing files that changed from the base of the PR and between 5a8808086a9815b67d4822cd20cf1e8a7a05f002 and 07b1b7f1d6acaa3a8135f55440ef6c6fdb0fdc90. </details> <details> <summary>📒 Files selected for processing (3)</summary> * `CMakeLists.txt` * `src/libs/libRtc.cpp` * `tests/RtcFormatTests.cpp` </details> **Included review availability:** This review used your included allowance. Your plan provides up to 8 included reviews per hour; 6 remain after this review. </details> <!-- This is an auto-generated comment by CodeRabbit for review status --> <!-- coderabbit-review-publication v1 publication=2ceef46a-37c4-46ff-884f-f741f1788d6f attempt=a24c7f75-d0ca-4dfd-bfe4-5edd8a1bbb8f batch=1/1 -->
@ -355,2 +443,4 @@
return RtcFormatRFC2822(date_time, utc, RTC_LOCAL_TIME_ZONE_MINUTES);
}
Author
Owner

@⁠overlordxrz-source on GitHub · 2026-10-08 02:48 UTC · original

Good catch, thanks. Fixed in "libRtc: reject RFC formatter output that does not fit in 32 bytes".

Both formatters now build the string in a local 32-byte buffer, check the snprintf result, and copy it to the guest buffer only when it fits. Otherwise they return RTC_ERROR_INVALID_VALUE and write nothing. sceRtcFormatRFC3339 had the same unchecked call, and its zone suffix was also cut off silently from 1000 hours up, so it gets the same check. The LocalTime variants share this code.

The tests now cover the longest offsets that still fit (+/-9959 for RFC 2822, +999:59 for RFC 3339). They also check that 6000 and 60000 minutes return INVALID_VALUE and leave the buffer untouched.

**@⁠overlordxrz-source** on GitHub · 2026-10-08 02:48 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1184#discussion_r4214093787) Good catch, thanks. Fixed in "libRtc: reject RFC formatter output that does not fit in 32 bytes". Both formatters now build the string in a local 32-byte buffer, check the snprintf result, and copy it to the guest buffer only when it fits. Otherwise they return RTC_ERROR_INVALID_VALUE and write nothing. sceRtcFormatRFC3339 had the same unchecked call, and its zone suffix was also cut off silently from 1000 hours up, so it gets the same check. The LocalTime variants share this code. The tests now cover the longest offsets that still fit (+/-9959 for RFC 2822, +999:59 for RFC 3339). They also check that 6000 and 60000 minutes return INVALID_VALUE and leave the buffer untouched.
@ -355,2 +443,4 @@
return RtcFormatRFC2822(date_time, utc, RTC_LOCAL_TIME_ZONE_MINUTES);
}
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-08 02:49 UTC · original

@overlordxrz-source Thanks for the fix. The updated code checks the formatted length before copying to the guest buffer. Both formatters now return RTC_ERROR_INVALID_VALUE without writing when the output does not fit. This addresses the finding.


If you found this review helpful, would you consider giving us a shout-out on X?

Thank you for using CodeRabbit!

✅ Review thread resolved.

You are interacting with an AI system.

**@⁠coderabbitai[bot]** on GitHub · 2026-10-08 02:49 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1184#discussion_r4214095384) `@overlordxrz-source` Thanks for the fix. The updated code checks the formatted length before copying to the guest buffer. Both formatters now return `RTC_ERROR_INVALID_VALUE` without writing when the output does not fit. This addresses the finding. --- <!-- This is an auto-generated comment: tweet message by coderabbit.ai --> If you found this review helpful, would you consider giving us a shout-out on [X](https://twitter.com/intent/tweet?related=CodeRabbitAI&text=Unchecked%20%60snprintf%60%20could%20return%20OK%20with%20truncated%20RFC%202822%2F3339%20dates.%20Both%20formatters%20now%20validate%20length%20and%20leave%20guest%20buffers%20untouched%20on%20failure.%20Try%20%40coderabbitai%20%F0%9F%94%8D&url=https%3A%2F%2Fgithub.com%2FKytyPS5%2FKytyPS5%2Fpull%2F1184%23discussion_r4214028021)? Thank you for using CodeRabbit! <!-- end of auto-generated comment: tweet message by coderabbit.ai --> ✅ Review thread resolved. _You are interacting with an AI system._ <!-- This is an auto-generated reply by CodeRabbit -->
@ -346,0 +384,4 @@
static_cast<int>(minutes % 60));
if (len < 0 || static_cast<size_t>(len) >= sizeof(zone)) {
return RTC_ERROR_INVALID_VALUE;
}
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-08 02:51 UTC · original · edited 2026-10-08 15:43 UTC

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Reject offsets outside the RFC 3339 hour range. A 24-hour offset fits the zone buffer, but RFC 3339 permits only 00–23 for offset hours. The current formatter returns success for +24:00, and the new test expects success for +999:59. Strict consumers can reject both timestamps. (rfc-editor.org)

  • src/libs/libRtc.cpp#L377-L382: reject offsets of 24 hours or more before formatting.
  • tests/RtcFormatTests.cpp#L138-L143: expect RTC_ERROR_INVALID_VALUE and an untouched buffer for out-of-range offsets.
📍 Affects 2 files
  • src/libs/libRtc.cpp#L377-L382 (this comment)
  • tests/RtcFormatTests.cpp#L138-L143

✅ Confirmed as addressed by @⁠overlordxrz-source

**@⁠coderabbitai[bot]** on GitHub · 2026-10-08 02:51 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1184#discussion_r4214105869) · edited 2026-10-08 15:43 UTC **🎯 Functional Correctness** | **🟡 Minor** | **⚡ Quick win** **Reject offsets outside the RFC 3339 hour range.** A 24-hour offset fits the zone buffer, but RFC 3339 permits only `00`–`23` for offset hours. The current formatter returns success for `+24:00`, and the new test expects success for `+999:59`. Strict consumers can reject both timestamps. ([rfc-editor.org](https://www.rfc-editor.org/info/rfc3339/)) - `src/libs/libRtc.cpp#L377-L382`: reject offsets of 24 hours or more before formatting. - `tests/RtcFormatTests.cpp#L138-L143`: expect `RTC_ERROR_INVALID_VALUE` and an untouched buffer for out-of-range offsets. <details> <summary>📍 Affects 2 files</summary> - `src/libs/libRtc.cpp#L377-L382` (this comment) - `tests/RtcFormatTests.cpp#L138-L143` </details> <!-- consolidated_sites_start --> <!-- <consolidated_sites> <site> <role>anchor</role> <file>src/libs/libRtc.cpp</file> <line_range>377-382</line_range> </site> <site> <role>sibling</role> <file>tests/RtcFormatTests.cpp</file> <line_range>138-143</line_range> </site> </consolidated_sites> --> <!-- consolidated_sites_end --> <!-- fingerprinting:phantom:poseidon:wombat --> <!-- cr-indicator-types:potential_issue --> <!-- cr-comment:v1:f1d66b2de452554c8b98b537 --> <!-- This is an auto-generated reply by CodeRabbit --> ✅ Confirmed as addressed by @⁠overlordxrz-source <!-- This is an auto-generated comment by CodeRabbit -->
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-08 02:51 UTC · original · reviewed

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository: KytyPS5/KytyPS5/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 14771b99-c4e6-41e5-addc-7b3fb4154383
📥 Commits

Reviewing files that changed from the base of the PR and between 07b1b7f1d6 and 810593da94.

📒 Files selected for processing (2)
  • src/libs/libRtc.cpp
  • tests/RtcFormatTests.cpp

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 3 remain after this review.

**@⁠coderabbitai[bot]** on GitHub · 2026-10-08 02:51 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1184#pullrequestreview-5450808195) · **reviewed** **Actionable comments posted: 1** --- <details> <summary>ℹ️ Review info</summary> <details> <summary>⚙️ Run configuration</summary> - **Configuration used**: Repository: KytyPS5/KytyPS5/.coderabbit.yaml - **Review profile**: CHILL - **Plan**: Advanced - **Run ID**: `14771b99-c4e6-41e5-addc-7b3fb4154383` </details> <details> <summary>📥 Commits</summary> Reviewing files that changed from the base of the PR and between 07b1b7f1d6acaa3a8135f55440ef6c6fdb0fdc90 and 810593da94ae1528410c9fd8da14dfc4c7d46c0e. </details> <details> <summary>📒 Files selected for processing (2)</summary> * `src/libs/libRtc.cpp` * `tests/RtcFormatTests.cpp` </details> **Included review availability:** This review used your included allowance. Your plan provides up to 8 included reviews per hour; 3 remain after this review. </details> <!-- This is an auto-generated comment by CodeRabbit for review status --> <!-- coderabbit-review-publication v1 publication=bc77a9d2-cd18-4736-a836-365d97926e32 attempt=b9411ee8-1fa2-43f1-a2fb-da9bd604dcdf batch=1/1 -->
@ -346,0 +384,4 @@
static_cast<int>(minutes % 60));
if (len < 0 || static_cast<size_t>(len) >= sizeof(zone)) {
return RTC_ERROR_INVALID_VALUE;
}
Author
Owner

@⁠overlordxrz-source on GitHub · 2026-10-08 15:43 UTC · original

Fixed in "libRtc: reject RFC 3339 offsets of 24 hours or more".

sceRtcFormatRFC3339 (and the LocalTime variant, which shares the code) now returns RTC_ERROR_INVALID_VALUE for an offset of 24 hours or more, before writing anything. The tests now accept +/-23:59 and expect INVALID_VALUE with an untouched buffer for +/-24:00 and 60000 minutes. With the old code the new checks fail; with the fix the test passes natively. I haven't checked what the console's own formatter does with such offsets.

**@⁠overlordxrz-source** on GitHub · 2026-10-08 15:43 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1184#discussion_r4221075592) Fixed in "libRtc: reject RFC 3339 offsets of 24 hours or more". sceRtcFormatRFC3339 (and the LocalTime variant, which shares the code) now returns RTC_ERROR_INVALID_VALUE for an offset of 24 hours or more, before writing anything. The tests now accept +/-23:59 and expect INVALID_VALUE with an untouched buffer for +/-24:00 and 60000 minutes. With the old code the new checks fail; with the fix the test passes natively. I haven't checked what the console's own formatter does with such offsets.
@ -346,0 +384,4 @@
static_cast<int>(minutes % 60));
if (len < 0 || static_cast<size_t>(len) >= sizeof(zone)) {
return RTC_ERROR_INVALID_VALUE;
}
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-08 15:43 UTC · original

@overlordxrz-source Thanks for the fix. The supplied code rejects offsets of ±24 hours or more before writing to the output buffer. Your reported tests cover ±23:59, ±24:00, and 60000 minutes, including unchanged buffers on rejection.

Console behavior remains unverified, but this addresses the RFC 3339 compliance finding.


If you found this review helpful, would you consider giving us a shout-out on X?

Thank you for using CodeRabbit!

✅ Review thread resolved.

You are interacting with an AI system.

**@⁠coderabbitai[bot]** on GitHub · 2026-10-08 15:43 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1184#discussion_r4221081662) `@overlordxrz-source` Thanks for the fix. The supplied code rejects offsets of ±24 hours or more before writing to the output buffer. Your reported tests cover ±23:59, ±24:00, and 60000 minutes, including unchanged buffers on rejection. Console behavior remains unverified, but this addresses the RFC 3339 compliance finding. --- <!-- This is an auto-generated comment: tweet message by coderabbit.ai --> If you found this review helpful, would you consider giving us a shout-out on [X](https://twitter.com/intent/tweet?related=CodeRabbitAI&text=RFC%203339%20formatters%20should%20reject%20offsets%20%E2%89%A524h%20with%20%60INVALID_VALUE%60%20before%20touching%20the%20buffer.%20Test%20%C2%B123%3A59%20and%20%C2%B124%3A00.%20%40coderabbitai%20catches%20edge%20cases%E2%80%94give%20it%20a%20try!%20%F0%9F%90%87&url=https%3A%2F%2Fgithub.com%2FKytyPS5%2FKytyPS5%2Fpull%2F1184%23discussion_r4214105869)? Thank you for using CodeRabbit! <!-- end of auto-generated comment: tweet message by coderabbit.ai --> ✅ Review thread resolved. _You are interacting with an AI system._ <!-- This is an auto-generated reply by CodeRabbit -->
This pull request has changes conflicting with the target branch.
  • src/libs/libRtc.cpp
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/1184/head:github-bot/gh-1184'
git switch 'github-bot/gh-1184'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-1184'
git switch 'github-bot/gh-1184'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-1184'
git switch 'github-bot/gh-1184'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-1184'
git switch 'main'
git merge --squash 'github-bot/gh-1184'
git switch 'main'
git merge --ff-only 'github-bot/gh-1184'
git switch 'main'
git merge 'github-bot/gh-1184'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.