test(libSceSaveData.native): cover offset boundaries, null buffers, and uninitialized access in save data memory #12846

Merged
slopgobblercobbler merged 1 commit from upstream-pr/12846 into main 2026-11-02 16:14:30 +00:00
slopgobblercobbler commented 2026-10-29 12:32:52 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by slopgobblercobbler on 2026-10-29T12:32:52Z.


What

  1. Zero-Length Request Parity:

    • Preserves main's behavior where zero-length requests (buf_size == 0) succeed without attempting I/O.
    • Retains Export.cpp unchanged, relying on the unsigned size_t cast to reject negative offsets whenever buf_size != 0.
  2. Test Coverage (core/libs/tests/GuestSaveDataPs4.cpp):

    • Pinned SAVE_DATA_ERROR_NOT_INITIALIZED error precedence for sceSaveDataGetSaveDataMemory and sceSaveDataSetSaveDataMemory prior to library initialization.
    • Pinned SAVE_DATA_ERROR_PARAMETER rejection for non-zero negative offsets (-1), non-zero out-of-bounds offsets (0x1001), and null buffers with non-zero request size.
    • Verified that zero-length requests (buf_size == 0) succeed with 0.
  3. Technical Debt Entry (docs/dev/debt/libSceSaveData.native.md):

    • Documents that retail console firmware behavior for non-zero out-of-bounds offsets, negative offsets, and null buffers in save data memory operations remains unmeasured against console diagnostics, while zero-length requests succeed without I/O.

Tested

  • Windows 11 x86_64: ctest --output-on-failure -R GuestSaveDataPs4 passed.
  • Verified by @JJenkx on Windows 11 Enterprise (Ryzen 9 5950X, WinLibs GCC 15.2.0 UCRT r7): guest_savedata_ps4 passed 3 of 3 (ctest --repeat until-fail:3), none skipped.
  • python tools/check_conventions.py --base upstream/main --head HEAD: 0 findings.

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:5068057912 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/12846). Originally posted by [slopgobblercobbler](https://github.com/slopgobblercobbler) on 2026-10-29T12:32:52Z. --- ### What 1. **Zero-Length Request Parity**: - Preserves `main`'s behavior where zero-length requests (`buf_size == 0`) succeed without attempting I/O. - Retains `Export.cpp` unchanged, relying on the unsigned `size_t` cast to reject negative offsets whenever `buf_size != 0`. 2. **Test Coverage (`core/libs/tests/GuestSaveDataPs4.cpp`)**: - Pinned `SAVE_DATA_ERROR_NOT_INITIALIZED` error precedence for `sceSaveDataGetSaveDataMemory` and `sceSaveDataSetSaveDataMemory` prior to library initialization. - Pinned `SAVE_DATA_ERROR_PARAMETER` rejection for non-zero negative offsets (`-1`), non-zero out-of-bounds offsets (`0x1001`), and null buffers with non-zero request size. - Verified that zero-length requests (`buf_size == 0`) succeed with `0`. 3. **Technical Debt Entry (`docs/dev/debt/libSceSaveData.native.md`)**: - Documents that retail console firmware behavior for non-zero out-of-bounds offsets, negative offsets, and null buffers in save data memory operations remains unmeasured against console diagnostics, while zero-length requests succeed without I/O. ### Tested - Windows 11 x86_64: `ctest --output-on-failure -R GuestSaveDataPs4` passed. - Verified by @JJenkx on Windows 11 Enterprise (Ryzen 9 5950X, WinLibs GCC 15.2.0 UCRT r7): `guest_savedata_ps4` passed 3 of 3 (`ctest --repeat until-fail:3`), none skipped. - `python tools/check_conventions.py --base upstream/main --head HEAD`: 0 findings. ### 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-29 12:54:17 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-29T12:54:17Z.

Review: CHANGES_REQUESTED


Reviewed — changes requested

The hosted conventions check fails on the PR description, and the new zero-length offset errors assert behavior the PR itself marks unmeasured.

What I ran

Reviewed head 7986d1ce87c7c47bccddfe2a30d4a79a884e9e228 against main at 5454cd2e455994d992aca39335ce60507eeda1eb; the merge preview is clean (542b09ae3caf56684bd2f6113888ab79a3444a60). I inspected the exact diff and current hosted checks. Local environment: Linux x86_64. I did not compile or run the C++ test target.

git merge-tree --write-tree upstream/main refs/remotes/upstream/pr/12846-review
git diff --check upstream/main...refs/remotes/upstream/pr/12846-review
python3 tools/check_conventions.py --base upstream/main --head refs/remotes/upstream/pr/12846-review
gh run view --log-failed --job=123448565739 -R boykopovar/AnyPS5
gh pr checks 12846 -R boykopovar/AnyPS5

Results

Check Result
Merge preview Pass; clean tree 542b09ae3caf56684bd2f6113888ab79a3444a60
git diff --check Pass; no output
Local source conventions invocation Pass, but it does not reproduce the hosted PR-description check
Hosted conventions Fail: the PR template ### What heading was not detected
Hosted Windows Pass
Hosted Linux and specialized jobs Skipped by workflow
Local C++ tests Not run
Raw local conventions output
All conventions checks passed.
Raw hosted conventions failure
##[error]Fill in the pull request template: add the '### What' heading of the template
1 findings, 1 errors; GitHub shows at most 10 error annotations, the job summary lists all
##[error]Process completed with exit code 1.

Negative control

Not run; I did not modify the code or test assertions.

Findings

Blocking

  1. The PR description starts with a UTF-8 BOM before ### What, so the hosted template check does not recognize the required heading. Remove the BOM and rerun the conventions check.
  2. getSaveDataMemory2 and setSaveDataMemory2 now return SAVE_DATA_ERROR_PARAMETER when offset > size, even when buf_size == 0. On the reviewed main, zero-length requests bypass range validation and return success. The new tests pin the changed result, while the new debt entry says the rule is unmeasured on console. Please provide console evidence for the zero-length out-of-range behavior or keep zero-length requests as no-ops.
  3. The scalar wrappers reject negative offsets before calling the initialized-state checks. That changes error precedence from SAVE_DATA_ERROR_NOT_INITIALIZED to SAVE_DATA_ERROR_PARAMETER for a negative call made before initialization. Please confirm the intended precedence with console evidence and test that order, or route the check through the initialized API path.

Non-blocking

The Windows workflow passes. The Linux build/test lane was skipped, so the checked-in test changes have not been verified in hosted Linux CI.

Sources

Not verified

  • No local C++ build or CTest run.
  • No console measurement or other firmware evidence for zero-length out-of-range calls or negative-offset error precedence.
  • Hosted Linux and specialized tests did not run.

To get this to a good state

Remove the description BOM, resolve the two unmeasured behavior changes with evidence or preserve the current zero-length and initialization behavior, and add a negative-offset-before-initialization test if that precedence is retained. I will rerun the same checks on the updated head.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5697994931 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/12846#pullrequestreview-5697994931). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-29T12:54:17Z. **Review:** CHANGES_REQUESTED --- # Reviewed — changes requested The hosted conventions check fails on the PR description, and the new zero-length offset errors assert behavior the PR itself marks unmeasured. ## What I ran Reviewed head `7986d1ce87c7c47bccddfe2a30d4a79a884e9e228` against `main` at `5454cd2e455994d992aca39335ce60507eeda1eb`; the merge preview is clean (`542b09ae3caf56684bd2f6113888ab79a3444a60`). I inspected the exact diff and current hosted checks. Local environment: Linux x86_64. I did not compile or run the C++ test target. ```sh git merge-tree --write-tree upstream/main refs/remotes/upstream/pr/12846-review git diff --check upstream/main...refs/remotes/upstream/pr/12846-review python3 tools/check_conventions.py --base upstream/main --head refs/remotes/upstream/pr/12846-review gh run view --log-failed --job=123448565739 -R boykopovar/AnyPS5 gh pr checks 12846 -R boykopovar/AnyPS5 ``` ## Results | Check | Result | |---|---| | Merge preview | Pass; clean tree `542b09ae3caf56684bd2f6113888ab79a3444a60` | | `git diff --check` | Pass; no output | | Local source conventions invocation | Pass, but it does not reproduce the hosted PR-description check | | Hosted conventions | Fail: the PR template `### What` heading was not detected | | Hosted Windows | Pass | | Hosted Linux and specialized jobs | Skipped by workflow | | Local C++ tests | Not run | <details> <summary>Raw local conventions output</summary> ```text All conventions checks passed. ``` </details> <details> <summary>Raw hosted conventions failure</summary> ```text ##[error]Fill in the pull request template: add the '### What' heading of the template 1 findings, 1 errors; GitHub shows at most 10 error annotations, the job summary lists all ##[error]Process completed with exit code 1. ``` </details> ## Negative control Not run; I did not modify the code or test assertions. ## Findings ### Blocking 1. The PR description starts with a UTF-8 BOM before `### What`, so the hosted template check does not recognize the required heading. Remove the BOM and rerun the conventions check. 2. `getSaveDataMemory2` and `setSaveDataMemory2` now return `SAVE_DATA_ERROR_PARAMETER` when `offset > size`, even when `buf_size == 0`. On the reviewed `main`, zero-length requests bypass range validation and return success. The new tests pin the changed result, while the new debt entry says the rule is unmeasured on console. Please provide console evidence for the zero-length out-of-range behavior or keep zero-length requests as no-ops. 3. The scalar wrappers reject negative offsets before calling the initialized-state checks. That changes error precedence from `SAVE_DATA_ERROR_NOT_INITIALIZED` to `SAVE_DATA_ERROR_PARAMETER` for a negative call made before initialization. Please confirm the intended precedence with console evidence and test that order, or route the check through the initialized API path. ### Non-blocking The Windows workflow passes. The Linux build/test lane was skipped, so the checked-in test changes have not been verified in hosted Linux CI. ## Sources - [Changed memory validation at head `7986d1ce87c7c47bccddfe2a30d4a79a884e9e228`](https://github.com/boykopovar/AnyPS5/blob/7986d1ce87c7c47bccddfe2a30d4a79a884e9e228/core/libs/prx/libSceSaveData.native/Export.cpp#L560-L606) - [Changed scalar wrappers at head `7986d1ce87c7c47bccddfe2a30d4a79a884e9e228`](https://github.com/boykopovar/AnyPS5/blob/7986d1ce87c7c47bccddfe2a30d4a79a884e9e228/core/libs/prx/libSceSaveData.native/Export.cpp#L1446-L1472) - [Current `main` behavior at `5454cd2e455994d992aca39335ce60507eeda1eb`](https://github.com/boykopovar/AnyPS5/blob/5454cd2e455994d992aca39335ce60507eeda1eb/core/libs/prx/libSceSaveData.native/Export.cpp#L560-L602) - [New tests at head `7986d1ce87c7c47bccddfe2a30d4a79a884e9e228`](https://github.com/boykopovar/AnyPS5/blob/7986d1ce87c7c47bccddfe2a30d4a79a884e9e228/core/libs/tests/GuestSaveDataPs4.cpp) - [Hosted conventions job](https://github.com/boykopovar/AnyPS5/actions/runs/40874161923/job/123448565739) ## Not verified - No local C++ build or CTest run. - No console measurement or other firmware evidence for zero-length out-of-range calls or negative-offset error precedence. - Hosted Linux and specialized tests did not run. ## To get this to a good state Remove the description BOM, resolve the two unmeasured behavior changes with evidence or preserve the current zero-length and initialization behavior, and add a negative-offset-before-initialization test if that precedence is retained. I will rerun the same checks on the updated 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!12846
No description provided.