fix(libSceRudp): check the context status arguments first and initialization before the id pointer #13871

Merged
zaryabzip merged 2 commits from upstream-pr/13871 into main 2026-11-01 05:06:41 +00:00
zaryabzip commented 2026-10-31 10:22:41 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by zaryabzip on 2026-10-31T10:22:41Z.


What

Replaces #13849, which the open-PR limit closed and GitHub won't reopen; same branch and head.

Two libSceRudp answers now follow the firmware readings on #13682.

sceRudpGetContextStatus(int ctxId, void* status, size_t size)

  • After the initialization check, a negative id, a null status or a size outside 1 to 0x30 returns 0x80770004, before the id is looked up.
  • size is 64 bits: @BunnyFl's second run refuses 0x100000010, which a uint32_t would cut to 0x10 and accept. main declared it uint32_t, as the 10.71 reading types it, so PS4 and PS5 may differ here.
  • An unknown id then returns 0x80770003.
  • On success it writes the first size bytes of a 0x30-byte block. The block is zero except for 0xFFFFFFFF at bytes 4-7, which is what the 13.42 run read for an idle context.

On main it accepted any size, returned 0 for a null pointer, checked the id first, and wrote zeros. Every context answers with the idle block here. The second run read the same block for a bound context, and 6 in bytes 0-3 for a listening one, which main can't produce yet (#13799 adds listening); the debt entry records it.

sceRudpCreateContext: before initialization, a null id pointer returns 0x80770001, as in the 13.42 run. main checked the pointer first and returned 0x80770004. It gets its own debt entry.

No function changes count.

GuestRudpContextLifecycle.cpp changes to match:

  • It used a 64-byte buffer and expected 64 zero bytes and success for a null pointer. It now checks the refusals with an unknown id and with a live one.
  • It checks the 0x30-byte block, a 6-byte partial read, and that bytes past size stay untouched.
  • It refuses a size of 0x100000010.
  • It adds sceRudpCreateContext(handler, NULL, NULL) before init.

Overlap: this doesn't depend on my other Rudp PRs (#13718, #13799, #13814). Against main 73f4f7e06e, git merge-tree merges it cleanly with each of them (#13799 at its new head 651808a48b), with #11042, with @ntamas94's docs-only #13844, and with every other open pull request that merges with main. #13844 records the same 10.71 reading in its own debt entry, so one of the two entries can go when the second lands.

Tested

Windows 11 (WinLibs MinGW-w64 GCC 15.2.0 UCRT r7, CMake 4.3.1, Ninja 1.13.2) and Ubuntu 24.04 on WSL2 (GCC 13.3.0, CMake 3.28.3, Ninja 1.11.1), both with the head e70388ccd5 merged into main 73f4f7e06e.

  • No warnings in Export.cpp, include/Api.hpp or GuestRudpContextLifecycle.cpp. Every file that includes Api.hpp rebuilds with no warnings, and so does each header compiled on its own.
  • ctest -R "guest_rudp|rudp_poll|guest_offline_imports": 7 of 7 pass on WSL2 and 8 of 8 on Windows (plus rudp_poll_wait_exception). guest_rudp_context_lifecycle passes 3 of 3 on --repeat until-fail:3.
  • Baseline for the size change: the previous head 553f1a82d2 with only the new test file aborts at the 0x100000010 row (line 191) on both hosts (Windows exit 0xc0000409, Linux SIGABRT), and GCC warns there that the size becomes 16.
  • Baseline for the rest, earlier: on main 1b91748340 with only the test change, guest_rudp_context_lifecycle aborts at sceRudpCreateContext(Handler, nullptr, nullptr) == notInitialized (line 127) on both hosts.
  • tools/check_conventions.py passes.

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 (Claude Code)
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5096668853 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/13871). Originally posted by [zaryabzip](https://github.com/zaryabzip) on 2026-10-31T10:22:41Z. --- ### What Replaces #13849, which the open-PR limit closed and GitHub won't reopen; same branch and head. Two libSceRudp answers now follow the firmware readings on #13682. **`sceRudpGetContextStatus(int ctxId, void* status, size_t size)`** - After the initialization check, a negative id, a null `status` or a `size` outside 1 to 0x30 returns `0x80770004`, before the id is looked up. - Source: @ntamas94's [reading of firmware 10.71's module](https://github.com/boykopovar/AnyPS5/issues/13682#issuecomment-6541579780), a PS4 one, read statically. - @BunnyFl's [13.42 run](https://github.com/boykopovar/AnyPS5/issues/13682#issuecomment-6537745577) gives the same size range and null refusal. - `size` is 64 bits: @BunnyFl's [second run](https://github.com/boykopovar/AnyPS5/issues/13682#issuecomment-6543610064) refuses 0x100000010, which a `uint32_t` would cut to 0x10 and accept. `main` declared it `uint32_t`, as the 10.71 reading types it, so PS4 and PS5 may differ here. - An unknown id then returns `0x80770003`. - On success it writes the first `size` bytes of a 0x30-byte block. The block is zero except for `0xFFFFFFFF` at bytes 4-7, which is what the 13.42 run read for an idle context. On `main` it accepted any size, returned 0 for a null pointer, checked the id first, and wrote zeros. Every context answers with the idle block here. The second run read the same block for a bound context, and 6 in bytes 0-3 for a listening one, which `main` can't produce yet (#13799 adds listening); the debt entry records it. **`sceRudpCreateContext`**: before initialization, a null id pointer returns `0x80770001`, as in the 13.42 run. `main` checked the pointer first and returned `0x80770004`. It gets its own debt entry. No function changes count. `GuestRudpContextLifecycle.cpp` changes to match: - It used a 64-byte buffer and expected 64 zero bytes and success for a null pointer. It now checks the refusals with an unknown id and with a live one. - It checks the 0x30-byte block, a 6-byte partial read, and that bytes past `size` stay untouched. - It refuses a size of 0x100000010. - It adds `sceRudpCreateContext(handler, NULL, NULL)` before init. Overlap: this doesn't depend on my other Rudp PRs (#13718, #13799, #13814). Against `main` 73f4f7e06e, `git merge-tree` merges it cleanly with each of them (#13799 at its new head 651808a48b), with #11042, with @ntamas94's docs-only #13844, and with every other open pull request that merges with `main`. #13844 records the same 10.71 reading in its own debt entry, so one of the two entries can go when the second lands. ### Tested <!-- OS, title or homebrew, what was checked. "Not tested" is a valid answer. A performance change: the summary lines of main and of this PR from the same machine and scene, with the traces attached, captured as the Performance report issue form describes. --> Windows 11 (WinLibs MinGW-w64 GCC 15.2.0 UCRT r7, CMake 4.3.1, Ninja 1.13.2) and Ubuntu 24.04 on WSL2 (GCC 13.3.0, CMake 3.28.3, Ninja 1.11.1), both with the head e70388ccd5 merged into `main` 73f4f7e06e. - No warnings in `Export.cpp`, `include/Api.hpp` or `GuestRudpContextLifecycle.cpp`. Every file that includes `Api.hpp` rebuilds with no warnings, and so does each header compiled on its own. - `ctest -R "guest_rudp|rudp_poll|guest_offline_imports"`: 7 of 7 pass on WSL2 and 8 of 8 on Windows (plus `rudp_poll_wait_exception`). `guest_rudp_context_lifecycle` passes 3 of 3 on `--repeat until-fail:3`. - Baseline for the size change: the previous head 553f1a82d2 with only the new test file aborts at the 0x100000010 row (line 191) on both hosts (Windows exit 0xc0000409, Linux SIGABRT), and GCC warns there that the size becomes 16. - Baseline for the rest, earlier: on `main` 1b91748340 with only the test change, `guest_rudp_context_lifecycle` aborts at `sceRudpCreateContext(Handler, nullptr, nullptr) == notInitialized` (line 127) on both hosts. - `tools/check_conventions.py` passes. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [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: <!-- #PR, or none --> none - [x] Fixes: <!-- issue it closes as Fixes #N, or none --> none - [x] Unblocks: <!-- title ID and Game bring-up discussion, e.g. PPSA01325 #3232, or none --> none - [x] GPUs tested: <!-- for AGC, shader recompiler or VideoOut changes: vendor, model, driver and OS of each GPU the GPU tests ran on; otherwise n/a --> n/a - [x] AI-assisted: <!-- yes / no --> yes (Claude Code)
MarcZX10 commented 2026-10-31 10:34:56 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-31T10:34:56Z.

Review: APPROVED


Reviewed — looks good

At head 553f1a82d2ccfb49369105d1914559826bf4b84a, the validation order and bounded status copy match the PR’s stated firmware evidence, with no blocker found.

What I ran

Reviewed head 553f1a82d2ccfb49369105d1914559826bf4b84a against base cf5a1805e50ceeccf6574abd98b13e9783c412c1; merge preview was clean against current main at fd31320e83fe417fa9c7fef792613653d9eb4f02. Environment: Linux x86_64, Python 3.11.2, GCC 12.2.0. No local build or C++ test was run.

python3 tools/pr_precheck.py --repo boykopovar/AnyPS5 --pr 13871
gh pr checks 13871 --repo boykopovar/AnyPS5

Results

Check Result
Diff check Passed
Conventions and PR template Passed
Merge preview Clean against current main
Hosted Windows Passed
Hosted conventions, intake, labels, eligibility, report and library portability Passed
Hosted Linux, relinker, ASAN and specialized jobs Skipped by workflow
Focused Linux tests Author reports 6/6 WSL2 checks and 7/7 Windows checks, including three repeated lifecycle runs; I did not reproduce them locally.
Convention-check stdout (verbatim)
All conventions checks passed.

Negative control

Assertion Change under test Result
sceRudpCreateContext(..., nullptr) before initialization returns RUDP_ERROR_NOT_INITIALIZED Author reports running the updated test against the base implementation with only the test change Failed on the base as expected on both WSL2 and Windows; not run by me

Findings

Blocking

None found.

Non-blocking

The current workflow skipped Linux, so the Linux-specific implementation path is supported here by the author’s reported WSL2 run rather than hosted CI or my own run.

Sources

Not verified

I did not run the C++ tests locally or verify behavior on console hardware. The Linux-specific path was not run by hosted CI.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5722373388 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/13871#pullrequestreview-5722373388). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-31T10:34:56Z. **Review:** APPROVED --- # Reviewed — looks good At head `553f1a82d2ccfb49369105d1914559826bf4b84a`, the validation order and bounded status copy match the PR’s stated firmware evidence, with no blocker found. ## What I ran Reviewed head `553f1a82d2ccfb49369105d1914559826bf4b84a` against base `cf5a1805e50ceeccf6574abd98b13e9783c412c1`; merge preview was clean against current `main` at `fd31320e83fe417fa9c7fef792613653d9eb4f02`. Environment: Linux x86_64, Python 3.11.2, GCC 12.2.0. No local build or C++ test was run. ```text python3 tools/pr_precheck.py --repo boykopovar/AnyPS5 --pr 13871 gh pr checks 13871 --repo boykopovar/AnyPS5 ``` ## Results | Check | Result | |---|---| | Diff check | Passed | | Conventions and PR template | Passed | | Merge preview | Clean against current `main` | | Hosted Windows | Passed | | Hosted conventions, intake, labels, eligibility, report and library portability | Passed | | Hosted Linux, relinker, ASAN and specialized jobs | Skipped by workflow | | Focused Linux tests | Author reports 6/6 WSL2 checks and 7/7 Windows checks, including three repeated lifecycle runs; I did not reproduce them locally. | <details><summary>Convention-check stdout (verbatim)</summary> ```text All conventions checks passed. ``` </details> ## Negative control | Assertion | Change under test | Result | |---|---|---| | `sceRudpCreateContext(..., nullptr)` before initialization returns `RUDP_ERROR_NOT_INITIALIZED` | Author reports running the updated test against the base implementation with only the test change | Failed on the base as expected on both WSL2 and Windows; not run by me | ## Findings ### Blocking None found. ### Non-blocking The current workflow skipped Linux, so the Linux-specific implementation path is supported here by the author’s reported WSL2 run rather than hosted CI or my own run. ## Sources - [Argument ordering and bounded status copy at the reviewed head](https://github.com/boykopovar/AnyPS5/blob/553f1a82d2ccfb49369105d1914559826bf4b84a/core/libs/prx/libSceRudp/Export.cpp#L225-L325) - [Firmware evidence for `sceRudpGetContextStatus`](https://github.com/boykopovar/AnyPS5/issues/13682#issuecomment-6541579780) - [Firmware evidence for `sceRudpCreateContext`](https://github.com/boykopovar/AnyPS5/issues/13682#issuecomment-6537745577) ## Not verified I did not run the C++ tests locally or verify behavior on console hardware. The Linux-specific path was not run by hosted CI.
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!13871
No description provided.