fix(ajm): bound private batch job reads before execution #9483
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/9483"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
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 headf212da8407f0615947e9168712bfa6a289ce49ee. Fresh CMake configure and Release GCC build ofguest_ajm_testsand dependencies passed, followed byctest --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 againstorigin/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_ajmsuite 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=libsverifies 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_testsand its dependencies also passed, followed by CTestguest_ajm(1/1) and a direct run withLD_DEBUG=libsconfirming 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 submodule9ac4cfd195f1. The complete application/library collection was not built. No title startup or performance improvement is claimed.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-21T23:17:23Z.
Review: APPROVED
Reviewed the parser and guarded-page regression.
sceAjmBatchStartnow 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 focusedguest_ajmruns plus a fresh targeted build; hosted full product builds were skipped, and the author explicitly says the whole application/library collection was not built.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_ajmruns, 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.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 ontomain; its merge-base isa6dcea927).ctest -R '^guest_ajm$'passes 3 of 3.libSceAjm.native/src/Ajm.cpprestored to the merge-base (the PR's tests kept): fails (SegFault).Not tested: macOS, Windows, a title run.
AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by tkcm01 on 2026-10-22T04:13:37Z.
Windows data point for
eb17d0099b, merged ontomaina6dcea927(clean merge). GitHub Actionswindows-latestrunning this repo's Build workflow (full Windows build, WinLibs GCC, Release,BUILD_TESTING=ON) on my fork.guest_ajmincluded (run).mainplus only this PR'score/libs/tests/GuestAjm.cpp: 1 of 236 fails,guest_ajm(***Exception: SegFault) (run).Not tested: Linux, macOS, a title.
AI-assisted: yes
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 isab347d144d. Please rebase and rerun the focusedguest_ajmtest 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.Imported from boykopovar/AnyPS5. Originally posted by JJenkx on 2026-10-22T04:55:22Z.
Rebased onto current main
524398151f1e1a7745bf41c4fdba9fd754508a97, nowf212da8407f0615947e9168712bfa6a289ce49ee, with one commit and no merge commits. A fresh configure/build ofguest_ajm_testsand dependencies passed, and focused CTestguest_ajmpassed 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.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)
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 intoRegisterBatch. When resolving the adjacent hunk, keep the bounds checks and remaining-byte advancement, then callRegisterBatchafter 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.