fix(ajm): bound private batch job reads before execution #9483

Merged
JJenkx merged 2 commits from upstream-pr/9483 into main 2026-10-25 17:08:46 +00:00
JJenkx commented 2026-10-21 23:04:55 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by JJenkx on 2026-10-21T23:04:55Z.


What

Bounds-check AJM's private packed batch records before copying their headers, buffer lists or parameters. Null batch storage and an offset beyond its capacity return the existing invalid-parameter error; truncated or inconsistent private records throw, since the console behavior for corrupted batches is unverified. Each accepted record must advance within the remaining bytes.

The tested baseline (a6dcea9279b53b3a39c13695eac66f7c8b5b503c) faults when a one-byte batch ends at a protected page boundary. The regression constructs a job through the existing batch builder and checks every truncated prefix at that boundary, plus zeroed/corrupt records and invalid descriptors. Valid decoder behavior remains covered by the existing suite.

The refreshed overlap checker could not compare two conflicting older branches. Manual review found that #3205 adds error strings and #6044 relocates tests; neither adds batch-record bounds checks. The earlier review of #9034 also found only WVorbis header changes. There is no functional dependency. The shared test/debt files may need an additive rebase as those land.

Tested

Rebased without merge commits onto upstream 524398151f1e1a7745bf41c4fdba9fd754508a97; PR head f212da8407f0615947e9168712bfa6a289ce49ee. Fresh CMake configure and Release GCC build of guest_ajm_tests and dependencies passed, followed by ctest --test-dir /mnt/sas-ssd/AnyPS5-work/workspace/ajm-batch-validation-20261021/fresh-cmake/build -R '^guest_ajm$' --no-tests=error -V: 1/1 passed (0.02 seconds). Conventions passed against origin/main. The overlap checker completed with the two manual-review limitations described above. Range-diff confirms the rebase preserves the original patch.

Earlier baseline comparison and validation:

Linux x86-64, Ryzen 9 7950X, GCC. The full guest_ajm suite including the new regression passes three consecutive runs. The identical test executable, with the unchanged main library (a6dcea9279b53b3a39c13695eac66f7c8b5b503c), terminates with SIGSEGV at the guarded truncation case. LD_DEBUG=libs verifies the AJM library loaded in each arm.

The changed AJM source, shared library and test were built in isolated output paths using the current main Ninja compile/link commands and its existing pinned dependency objects. A separate fresh CMake configure and build of guest_ajm_tests and its dependencies also passed, followed by CTest guest_ajm (1/1) and a direct run with LD_DEBUG=libs confirming the newly built AJM library. This build used private source copies of the pinned submodules, a fresh build directory, ccache and the cached FFmpeg package for submodule 9ac4cfd195f1. The complete application/library collection was not built. No title startup or performance improvement is claimed.

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:4959537547 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9483). Originally posted by [JJenkx](https://github.com/JJenkx) on 2026-10-21T23:04:55Z. --- ### What Bounds-check AJM's private packed batch records before copying their headers, buffer lists or parameters. Null batch storage and an offset beyond its capacity return the existing invalid-parameter error; truncated or inconsistent private records throw, since the console behavior for corrupted batches is unverified. Each accepted record must advance within the remaining bytes. The tested baseline (`a6dcea9279b53b3a39c13695eac66f7c8b5b503c`) faults when a one-byte batch ends at a protected page boundary. The regression constructs a job through the existing batch builder and checks every truncated prefix at that boundary, plus zeroed/corrupt records and invalid descriptors. Valid decoder behavior remains covered by the existing suite. The refreshed overlap checker could not compare two conflicting older branches. Manual review found that #3205 adds error strings and #6044 relocates tests; neither adds batch-record bounds checks. The earlier review of #9034 also found only WVorbis header changes. There is no functional dependency. The shared test/debt files may need an additive rebase as those land. ### Tested Rebased without merge commits onto upstream `524398151f1e1a7745bf41c4fdba9fd754508a97`; PR head `f212da8407f0615947e9168712bfa6a289ce49ee`. Fresh CMake configure and Release GCC build of `guest_ajm_tests` and dependencies passed, followed by `ctest --test-dir /mnt/sas-ssd/AnyPS5-work/workspace/ajm-batch-validation-20261021/fresh-cmake/build -R '^guest_ajm$' --no-tests=error -V`: 1/1 passed (0.02 seconds). Conventions passed against `origin/main`. The overlap checker completed with the two manual-review limitations described above. Range-diff confirms the rebase preserves the original patch. Earlier baseline comparison and validation: Linux x86-64, Ryzen 9 7950X, GCC. The full `guest_ajm` suite including the new regression passes three consecutive runs. The identical test executable, with the unchanged main library (`a6dcea9279b53b3a39c13695eac66f7c8b5b503c`), terminates with SIGSEGV at the guarded truncation case. `LD_DEBUG=libs` verifies the AJM library loaded in each arm. The changed AJM source, shared library and test were built in isolated output paths using the current main Ninja compile/link commands and its existing pinned dependency objects. A separate fresh CMake configure and build of `guest_ajm_tests` and its dependencies also passed, followed by CTest `guest_ajm` (1/1) and a direct run with `LD_DEBUG=libs` confirming the newly built AJM library. This build used private source copies of the pinned submodules, a fresh build directory, ccache and the cached FFmpeg package for submodule `9ac4cfd195f1`. The complete application/library collection was not built. No title startup or performance improvement is claimed. <!-- 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. --> ### 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: none - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
MarcZX10 commented 2026-10-21 23:17:23 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-21T23:17:23Z.

Review: APPROVED


Reviewed the parser and guarded-page regression. sceAjmBatchStart now rejects missing storage and an offset beyond the declared capacity before forming the end pointer; it checks the remaining bytes before reading each packed header, then verifies the parameter limit, complete buffer/parameter footprint and that the record stays within the remaining range before copying or executing it. The subtraction-based cursor advancement avoids walking beyond the declared batch offset. The regression places every truncated prefix of a valid serialized job at a protected page boundary, checks corrupt zero/all-ones records and verifies invalid descriptors leave the batch output unchanged. The implementation records the unverified malformed-private-record behavior in AJM debt and throws rather than inventing a console result. Conventions, intake, eligibility, labels and the progress report pass. The PR reports three focused guest_ajm runs plus a fresh targeted build; hosted full product builds were skipped, and the author explicitly says the whole application/library collection was not built.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5607398324 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9483#pullrequestreview-5607398324). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-21T23:17:23Z. **Review:** APPROVED --- Reviewed the parser and guarded-page regression. `sceAjmBatchStart` now rejects missing storage and an offset beyond the declared capacity before forming the end pointer; it checks the remaining bytes before reading each packed header, then verifies the parameter limit, complete buffer/parameter footprint and that the record stays within the remaining range before copying or executing it. The subtraction-based cursor advancement avoids walking beyond the declared batch offset. The regression places every truncated prefix of a valid serialized job at a protected page boundary, checks corrupt zero/all-ones records and verifies invalid descriptors leave the batch output unchanged. The implementation records the unverified malformed-private-record behavior in AJM debt and throws rather than inventing a console result. Conventions, intake, eligibility, labels and the progress report pass. The PR reports three focused `guest_ajm` runs plus a fresh targeted build; hosted full product builds were skipped, and the author explicitly says the whole application/library collection was not built.
MarcZX10 commented 2026-10-22 02:16:16 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-22T02:16:16Z.

Review: APPROVED


Reviewed the batch-bound checks and regression. The code rejects null storage and offset beyond capacity before forming a range, verifies enough bytes remain before reading each header, checks parameter and buffer footprints plus per-record bounds before copying/executing, and advances using the validated record size. The test exercises every truncated prefix at a no-access page boundary, malformed records, invalid descriptors and unchanged result/batch outputs. The author records malformed private-record behavior as unverified and throws instead of fabricating a result. Their report includes three guest_ajm runs, the main negative control, and a fresh targeted build; full application libraries were not built. Hosted policy checks pass, product/relinker jobs are skipped. I did not run local tests.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5608512168 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9483#pullrequestreview-5608512168). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-22T02:16:16Z. **Review:** APPROVED --- Reviewed the batch-bound checks and regression. The code rejects null storage and offset beyond capacity before forming a range, verifies enough bytes remain before reading each header, checks parameter and buffer footprints plus per-record bounds before copying/executing, and advances using the validated record size. The test exercises every truncated prefix at a no-access page boundary, malformed records, invalid descriptors and unchanged result/batch outputs. The author records malformed private-record behavior as unverified and throws instead of fabricating a result. Their report includes three `guest_ajm` runs, the main negative control, and a fresh targeted build; full application libraries were not built. Hosted policy checks pass, product/relinker jobs are skipped. I did not run local tests.
xXPBSXx commented 2026-10-22 04:12:04 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-22T04:12:04Z.


Linux data point for eb17d0099b: WSL2 Ubuntu 24.04 (virtualised kernel, not bare-metal), GCC 13.3.0, Release, BUILD_TESTING=ON, PR head alone (not merged onto main; its merge-base is a6dcea927).

  • With the PR: ctest -R '^guest_ajm$' passes 3 of 3.
  • With libSceAjm.native/src/Ajm.cpp restored to the merge-base (the PR's tests kept): fails (SegFault).
    Not tested: macOS, Windows, a title run.
    AI-assisted (Claude Code).
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6332498924 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9483#issuecomment-6332498924). Originally posted by [xXPBSXx](https://github.com/xXPBSXx) on 2026-10-22T04:12:04Z. --- Linux data point for `eb17d0099b`: WSL2 Ubuntu 24.04 (virtualised kernel, not bare-metal), GCC 13.3.0, Release, `BUILD_TESTING=ON`, PR head alone (not merged onto `main`; its merge-base is `a6dcea927`). - With the PR: `ctest -R '^guest_ajm$'` passes 3 of 3. - With `libSceAjm.native/src/Ajm.cpp` restored to the merge-base (the PR's tests kept): fails (`SegFault`). Not tested: macOS, Windows, a title run. AI-assisted (Claude Code).
tkcm01 commented 2026-10-22 04:13:37 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by tkcm01 on 2026-10-22T04:13:37Z.


Windows data point for eb17d0099b, merged onto main a6dcea927 (clean merge). GitHub Actions windows-latest running this repo's Build workflow (full Windows build, WinLibs GCC, Release, BUILD_TESTING=ON) on my fork.

  • With the PR: 238 tests, all pass, guest_ajm included (run).
  • Negative control, main plus only this PR's core/libs/tests/GuestAjm.cpp: 1 of 236 fails, guest_ajm (***Exception: SegFault) (run).
    Not tested: Linux, macOS, a title.
    AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6332518944 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9483#issuecomment-6332518944). Originally posted by [tkcm01](https://github.com/tkcm01) on 2026-10-22T04:13:37Z. --- Windows data point for `eb17d0099b`, merged onto `main` `a6dcea927` (clean merge). GitHub Actions `windows-latest` running this repo's Build workflow (full Windows build, WinLibs GCC, Release, `BUILD_TESTING=ON`) on my fork. - With the PR: 238 tests, all pass, `guest_ajm` included ([run](https://github.com/tkcm01/AnyPS5/actions/runs/39698549885)). - Negative control, `main` plus only this PR's `core/libs/tests/GuestAjm.cpp`: 1 of 236 fails, `guest_ajm` (`***Exception: SegFault`) ([run](https://github.com/tkcm01/AnyPS5/actions/runs/39698556871)). Not tested: Linux, macOS, a title. AI-assisted: yes
MarcZX10 commented 2026-10-22 04:29:43 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-22T04:29:43Z.

Review: DISMISSED


The private-record bounds checks and guarded-page regression are well supported: the PR reports repeated focused runs, a main negative control that segfaults at the same case, a fresh targeted build, and separate Linux/Windows evidence. The manual overlap note identifies #3205 as error strings, #6044 as test relocation and #9034 as headers, with no competing bounds logic. The branch/test evidence is based on a6dcea9279, while current upstream main is ab347d144d. Please rebase and rerun the focused guest_ajm test plus conventions and overlap checks on current main, preserving the shared test/debt changes. Hosted full product jobs are skipped; I did not run local tests.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5609274921 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9483#pullrequestreview-5609274921). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-22T04:29:43Z. **Review:** DISMISSED --- The private-record bounds checks and guarded-page regression are well supported: the PR reports repeated focused runs, a main negative control that segfaults at the same case, a fresh targeted build, and separate Linux/Windows evidence. The manual overlap note identifies #3205 as error strings, #6044 as test relocation and #9034 as headers, with no competing bounds logic. The branch/test evidence is based on a6dcea9279, while current upstream main is ab347d144d88fae054d9770cf0db8d3565735c02. Please rebase and rerun the focused `guest_ajm` test plus conventions and overlap checks on current main, preserving the shared test/debt changes. Hosted full product jobs are skipped; I did not run local tests.
JJenkx commented 2026-10-22 04:55:22 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by JJenkx on 2026-10-22T04:55:22Z.


Rebased onto current main 524398151f1e1a7745bf41c4fdba9fd754508a97, now f212da8407f0615947e9168712bfa6a289ce49ee, with one commit and no merge commits. A fresh configure/build of guest_ajm_tests and dependencies passed, and focused CTest guest_ajm passed 1/1. Conventions passed. The overlap checker completed; #3205 adds error-string tests and #6044 relocates tests, so neither implements the private batch bounds checks. Those branches conflict with main, so their shared test-file changes were reviewed manually. The description now distinguishes the earlier guarded-page baseline comparison from this refreshed build/test.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6333055046 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9483#issuecomment-6333055046). Originally posted by [JJenkx](https://github.com/JJenkx) on 2026-10-22T04:55:22Z. --- Rebased onto current main `524398151f1e1a7745bf41c4fdba9fd754508a97`, now `f212da8407f0615947e9168712bfa6a289ce49ee`, with one commit and no merge commits. A fresh configure/build of `guest_ajm_tests` and dependencies passed, and focused CTest `guest_ajm` passed 1/1. Conventions passed. The overlap checker completed; #3205 adds error-string tests and #6044 relocates tests, so neither implements the private batch bounds checks. Those branches conflict with main, so their shared test-file changes were reviewed manually. The description now distinguishes the earlier guarded-page baseline comparison from this refreshed build/test.
ntamas94 commented 2026-10-22 13:35:12 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ntamas94 on 2026-10-22T13:35:12Z.


#9637 (PS4 batch buffers through libSceAjm) touches the end of sceAjmBatchStart's job loop, where this PR bounds the reads: three lines will conflict. Since this one is older and smaller, I propose it lands first; I rebase #9637 the same day and list it under Depends on there. If you would rather have #9637 go first, say so and I keep the loop's shape for you to rebase onto.

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6342093566 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9483#issuecomment-6342093566). Originally posted by [ntamas94](https://github.com/ntamas94) on 2026-10-22T13:35:12Z. --- #9637 (PS4 batch buffers through libSceAjm) touches the end of `sceAjmBatchStart`'s job loop, where this PR bounds the reads: three lines will conflict. Since this one is older and smaller, I propose it lands first; I rebase #9637 the same day and list it under Depends on there. If you would rather have #9637 go first, say so and I keep the loop's shape for you to rebase onto. AI-assisted: yes (Claude Code)
JJenkx commented 2026-10-22 13:39:31 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by JJenkx on 2026-10-22T13:39:31Z.


@ntamas94 agreed: #9483 first, then rebase #9637 as you proposed. I checked both current patches: #9483 changes the private-job cursor advancement to subtract the validated record size from remaining; #9637 extracts the completed-batch registration into RegisterBatch. When resolving the adjacent hunk, keep the bounds checks and remaining-byte advancement, then call RegisterBatch after the loop.

Thanks for listing the landing order in #9637. These implement different behavior; no combined build or test result is claimed from this source review.

AI-assisted: yes (Codex); author responsible.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6342186326 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9483#issuecomment-6342186326). Originally posted by [JJenkx](https://github.com/JJenkx) on 2026-10-22T13:39:31Z. --- @ntamas94 agreed: #9483 first, then rebase #9637 as you proposed. I checked both current patches: #9483 changes the private-job cursor advancement to subtract the validated record size from `remaining`; #9637 extracts the completed-batch registration into `RegisterBatch`. When resolving the adjacent hunk, keep the bounds checks and remaining-byte advancement, then call `RegisterBatch` after the loop. Thanks for listing the landing order in #9637. These implement different behavior; no combined build or test result is claimed from this source review. AI-assisted: yes (Codex); author responsible.
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!9483
No description provided.