fix(libSceAppContent): guard integer parameter output #18516

Merged
Ducengarth merged 2 commits from upstream-pr/18516 into main 2026-11-12 12:29:07 +00:00
Ducengarth commented 2026-11-11 19:44:45 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Ducengarth on 2026-11-11T19:44:45Z.


What

sceAppContentAppParamGetInt directly stored the SKU flag or a user-defined parameter through the guest output pointer. An inaccessible non-null output could terminate the host process. Resolve the existing parameter value into a local and write its four bytes with GuestCopyOut_nid_no_patch, preserving the copy's incoming errno.

Keep initialization, null-output and unknown-ID precedence unchanged. If a checked copy fails, return SCE_APP_CONTENT_ERROR_PARAMETER, the code this export already returns for a null output and the one sceAppContentGetGameTrialsFlag returns when the same checked copy fails. The console's result for invalid memory is unmeasured, so the debt file records the code as a host-safety fallback.

Extend the existing AppContent regression across all five supported IDs, requiring SCE_APP_CONTENT_ERROR_PARAMETER and preserved errno for inaccessible output, the same values for valid output, unchanged surrounding canaries and preserved errno. Also check an inaccessible output before initialization and with an unsupported ID.

Tested

  • Windows, WinLibs GCC 15.2.0, Ninja Release, BUILD_TESTING=ON, full runtime configuration, based on 65351c2931ec7ed2be6a434d86468b897df3e0d1.
  • Built guest_appcontent_tests, guest_appcontent_download_tests, guest_appcontent_license_tests and guest_appcontent_entitlements_tests against the real libraries and dependencies.
  • Negative control: the new test with unchanged main production code causes guest_appcontent to fail with host access violation 0xc0000005, writing address 0x10; the other seven AppContent cases pass.
  • With the fix, ctest --test-dir <build> -R '^guest_appcontent($|_)' --output-on-failure: 8/8 passed. Refreshed the staged Windows test library after the incremental rebuild so the tests load the newly built module.
  • After review, head 29cb3ecef8 returns SCE_APP_CONTENT_ERROR_PARAMETER on a failed copy: rebuilt all four AppContent test executables on the same Windows machine and ran ctest --test-dir build -R '^guest_appcontent' 3 times, 8/8 passed each time.
  • No title, console or GPU run; no performance claim.
  • python tools/check_conventions.py --base upstream/main with this title and body passes. The required --base origin/main check was also run: the fork's stale main includes four pre-existing non-conventional subjects in the comparison (d95f1b7e5c, a9aa6f2f04, d9c8fd3a8d, 84a205981a); none belongs to this PR.
  • python tools/pr_overlap.py --branch codex/fix-app-content-param-output --repo boykopovar/AnyPS5 --jobs 8 scanned 1,981 open PRs and found no confirmed line/export overlap. It failed closed only on #14212's existing conflicts with the base. Manually compared its current head 6b4941bfe250142672c12b48b7b6c706b9691452: the shared AppContent debt file only gains spacing and removes a derived export count; that PR changes neither this function nor its regression. This new debt paragraph is separate from those edits. #17955 guards the add-on list getter and does not implement this integer-parameter fix.

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:5265784134 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/18516). Originally posted by [Ducengarth](https://github.com/Ducengarth) on 2026-11-11T19:44:45Z. --- ### What `sceAppContentAppParamGetInt` directly stored the SKU flag or a user-defined parameter through the guest output pointer. An inaccessible non-null output could terminate the host process. Resolve the existing parameter value into a local and write its four bytes with `GuestCopyOut_nid_no_patch`, preserving the copy's incoming `errno`. Keep initialization, null-output and unknown-ID precedence unchanged. If a checked copy fails, return `SCE_APP_CONTENT_ERROR_PARAMETER`, the code this export already returns for a null output and the one `sceAppContentGetGameTrialsFlag` returns when the same checked copy fails. The console's result for invalid memory is unmeasured, so the debt file records the code as a host-safety fallback. Extend the existing AppContent regression across all five supported IDs, requiring `SCE_APP_CONTENT_ERROR_PARAMETER` and preserved `errno` for inaccessible output, the same values for valid output, unchanged surrounding canaries and preserved `errno`. Also check an inaccessible output before initialization and with an unsupported ID. ### 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, WinLibs GCC 15.2.0, Ninja Release, `BUILD_TESTING=ON`, full runtime configuration, based on `65351c2931ec7ed2be6a434d86468b897df3e0d1`. - Built `guest_appcontent_tests`, `guest_appcontent_download_tests`, `guest_appcontent_license_tests` and `guest_appcontent_entitlements_tests` against the real libraries and dependencies. - Negative control: the new test with unchanged `main` production code causes `guest_appcontent` to fail with host access violation `0xc0000005`, writing address `0x10`; the other seven AppContent cases pass. - With the fix, `ctest --test-dir <build> -R '^guest_appcontent($|_)' --output-on-failure`: **8/8 passed**. Refreshed the staged Windows test library after the incremental rebuild so the tests load the newly built module. - After review, head `29cb3ecef8` returns `SCE_APP_CONTENT_ERROR_PARAMETER` on a failed copy: rebuilt all four AppContent test executables on the same Windows machine and ran `ctest --test-dir build -R '^guest_appcontent'` 3 times, **8/8 passed** each time. - No title, console or GPU run; no performance claim. - `python tools/check_conventions.py --base upstream/main` with this title and body passes. The required `--base origin/main` check was also run: the fork's stale `main` includes four pre-existing non-conventional subjects in the comparison (`d95f1b7e5c`, `a9aa6f2f04`, `d9c8fd3a8d`, `84a205981a`); none belongs to this PR. - `python tools/pr_overlap.py --branch codex/fix-app-content-param-output --repo boykopovar/AnyPS5 --jobs 8` scanned 1,981 open PRs and found no confirmed line/export overlap. It failed closed only on #14212's existing conflicts with the base. Manually compared its current head `6b4941bfe250142672c12b48b7b6c706b9691452`: the shared AppContent debt file only gains spacing and removes a derived export count; that PR changes neither this function nor its regression. This new debt paragraph is separate from those edits. #17955 guards the add-on list getter and does not implement this integer-parameter fix. ### 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
PrivacyOnion commented 2026-11-12 06:08:27 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-12T06:08:27Z.

Review: APPROVED


Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against d2add95476:

  • Conventions: tools/check_conventions.py passed; git diff --check clean.
  • Build: guest_appcontent_tests built cleanly.
  • CTest (guest_appcontent_download_0, guest_appcontent_download_1, guest_appcontent_download_18014398509481983, guest_appcontent_download_18014398509481984, guest_appcontent_download_18446744073709551615, guest_appcontent, guest_appcontent_license, guest_appcontent_entitlements):
    1/8 Test #2840: guest_appcontent_download_0 ......................   Passed    0.04 sec
    2/8 Test #2841: guest_appcontent_download_1 ......................   Passed    0.03 sec
    3/8 Test #2842: guest_appcontent_download_18014398509481983 ......   Passed    0.03 sec
    4/8 Test #2843: guest_appcontent_download_18014398509481984 ......   Passed    0.03 sec
    5/8 Test #2844: guest_appcontent_download_18446744073709551615 ...   Passed    0.03 sec
    6/8 Test #2846: guest_appcontent_license .........................   Passed    0.03 sec
    7/8 Test #2847: guest_appcontent_entitlements ....................   Passed    0.03 sec
    8/8 Test #2845: guest_appcontent .................................   Passed    0.03 sec
    100% tests passed, 0 tests failed out of 8
    
  • Negative control: with core/libs/prx/libSceAppContent/Export.cpp reverted to main and the new tests kept, the suite fails:
    2/8 Test #2841: guest_appcontent_download_1 ......................   Passed    0.03 sec
    3/8 Test #2847: guest_appcontent_entitlements ....................   Passed    0.02 sec
    4/8 Test #2844: guest_appcontent_download_18446744073709551615 ...   Passed    0.04 sec
    5/8 Test #2842: guest_appcontent_download_18014398509481983 ......   Passed    0.06 sec
    6/8 Test #2846: guest_appcontent_license .........................   Passed    0.06 sec
    7/8 Test #2843: guest_appcontent_download_18014398509481984 ......   Passed    0.04 sec
    8/8 Test #2845: guest_appcontent .................................***Exception: SegFault  0.39 sec
    88% tests passed, 1 tests failed out of 8
    
    Restoring the change makes it pass again.
  • Code reading:
    • Verified in core/libs/prx/libSceAppContent/Export.cpp that sceAppContentAppParamGetInt maintains exact validation precedence: uninitialized state returns SCE_APP_CONTENT_ERROR_NOT_INITIALIZED (0x80D90001) and null value returns SCE_APP_CONTENT_ERROR_PARAMETER (0x80D90002) before parameter ID resolution or memory operations.
    • Verified in core/libs/prx/libSceAppContent/Export.cpp that parameter ID dispatch correctly resolves APPPARAM_ID_SKU_FLAG (0) to SKU_FLAG_FULL (3) and IDs 1..4 to GetAppUserDefinedParam_nid_postfix(param_id - 1), while out-of-range IDs return SCE_APP_CONTENT_ERROR_PARAMETER prior to invoking GuestCopyOut_nid_no_patch.
    • Verified in core/libs/prx/libSceAppContent/Export.cpp that output writing uses GuestCopyOut_nid_no_patch(value, &result, sizeof(result)), saves and restores errno across the copy, and calls NotImplemented_nid_no_patch(func) on copy failure to avoid assigning an unmeasured guest error code.
    • Verified that no comments were added to source or test files and that the unmeasured hardware behavior on inaccessible output writes is documented in docs/dev/debt/libSceAppContent.md in compliance with AGENTS.md.
    • Verified in core/libs/tests/GuestAppContent.cpp that regression tests comprehensively validate inaccessible pointers before initialization, invalid parameter IDs with inaccessible pointers, NotImplemented exception throwing across IDs 0..4, exact output values with canary buffers, and errno preservation.

Looks Good To Me

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5869882401 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/18516#pullrequestreview-5869882401). Originally posted by [PrivacyOnion](https://github.com/PrivacyOnion) on 2026-11-12T06:08:27Z. **Review:** APPROVED --- Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against `d2add95476`: - **Conventions**: `tools/check_conventions.py` passed; `git diff --check` clean. - **Build**: `guest_appcontent_tests` built cleanly. - **CTest** (`guest_appcontent_download_0`, `guest_appcontent_download_1`, `guest_appcontent_download_18014398509481983`, `guest_appcontent_download_18014398509481984`, `guest_appcontent_download_18446744073709551615`, `guest_appcontent`, `guest_appcontent_license`, `guest_appcontent_entitlements`): ``` 1/8 Test #2840: guest_appcontent_download_0 ...................... Passed 0.04 sec 2/8 Test #2841: guest_appcontent_download_1 ...................... Passed 0.03 sec 3/8 Test #2842: guest_appcontent_download_18014398509481983 ...... Passed 0.03 sec 4/8 Test #2843: guest_appcontent_download_18014398509481984 ...... Passed 0.03 sec 5/8 Test #2844: guest_appcontent_download_18446744073709551615 ... Passed 0.03 sec 6/8 Test #2846: guest_appcontent_license ......................... Passed 0.03 sec 7/8 Test #2847: guest_appcontent_entitlements .................... Passed 0.03 sec 8/8 Test #2845: guest_appcontent ................................. Passed 0.03 sec 100% tests passed, 0 tests failed out of 8 ``` - **Negative control**: with `core/libs/prx/libSceAppContent/Export.cpp` reverted to `main` and the new tests kept, the suite fails: ``` 2/8 Test #2841: guest_appcontent_download_1 ...................... Passed 0.03 sec 3/8 Test #2847: guest_appcontent_entitlements .................... Passed 0.02 sec 4/8 Test #2844: guest_appcontent_download_18446744073709551615 ... Passed 0.04 sec 5/8 Test #2842: guest_appcontent_download_18014398509481983 ...... Passed 0.06 sec 6/8 Test #2846: guest_appcontent_license ......................... Passed 0.06 sec 7/8 Test #2843: guest_appcontent_download_18014398509481984 ...... Passed 0.04 sec 8/8 Test #2845: guest_appcontent .................................***Exception: SegFault 0.39 sec 88% tests passed, 1 tests failed out of 8 ``` Restoring the change makes it pass again. - **Code reading**: - Verified in core/libs/prx/libSceAppContent/Export.cpp that sceAppContentAppParamGetInt maintains exact validation precedence: uninitialized state returns SCE_APP_CONTENT_ERROR_NOT_INITIALIZED (0x80D90001) and null value returns SCE_APP_CONTENT_ERROR_PARAMETER (0x80D90002) before parameter ID resolution or memory operations. - Verified in core/libs/prx/libSceAppContent/Export.cpp that parameter ID dispatch correctly resolves APPPARAM_ID_SKU_FLAG (0) to SKU_FLAG_FULL (3) and IDs 1..4 to GetAppUserDefinedParam_nid_postfix(param_id - 1), while out-of-range IDs return SCE_APP_CONTENT_ERROR_PARAMETER prior to invoking GuestCopyOut_nid_no_patch. - Verified in core/libs/prx/libSceAppContent/Export.cpp that output writing uses GuestCopyOut_nid_no_patch(value, &result, sizeof(result)), saves and restores errno across the copy, and calls NotImplemented_nid_no_patch(__func__) on copy failure to avoid assigning an unmeasured guest error code. - Verified that no comments were added to source or test files and that the unmeasured hardware behavior on inaccessible output writes is documented in docs/dev/debt/libSceAppContent.md in compliance with AGENTS.md. - Verified in core/libs/tests/GuestAppContent.cpp that regression tests comprehensively validate inaccessible pointers before initialization, invalid parameter IDs with inaccessible pointers, NotImplemented exception throwing across IDs 0..4, exact output values with canary buffers, and errno preservation. Looks Good To Me
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!18516
No description provided.