fix(libSceAjm): check batch job buffer counts before the 8-bit cast #15321

Merged
MarcZX10 merged 2 commits from upstream-pr/15321 into main 2026-11-03 19:13:05 +00:00
MarcZX10 commented 2026-11-02 23:56:16 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-02T23:56:16Z.


What

sceAjmBatchJob buffer counts were truncated to 8 bits before the range check in JobRejected. A count that wraps past 32 bits (for example 2^32 + 1) passed as a small valid value. The count is now checked at full width, and counts that do not fit are refused.

Commits:

  • 96e2a7e576 fix(libSceAjm): check batch job buffer counts before the 8-bit cast
  • 9b20e4eb70 test(libSceAjm): refuse batch job buffer counts that wrap past 32 bits

Tested

  • Host: Linux, archive build, lane 1, on the final head (rebased onto current main).
  • ctest -R '^guest_ajm$': 1 of 1 passed (guest_ajm, Test #2204).
  • tools/check_conventions.py --base upstream/main and git diff --check upstream/main: clean.

Not verified

  • Negative control (old code, new test) not run.
  • The refusal code (INVALID_PARAMETER) follows the existing range check; the console value is not measured.
  • The Vorbis byte-rate overflow found in the same audit is not in this PR; it overlaps open #15021 and will be a follow-up.

Checklist

  • Based on current main; no other open PR changes this check
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Depends on: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5129365593 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/15321). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-02T23:56:16Z. --- ### What `sceAjmBatchJob` buffer counts were truncated to 8 bits before the range check in `JobRejected`. A count that wraps past 32 bits (for example `2^32 + 1`) passed as a small valid value. The count is now checked at full width, and counts that do not fit are refused. Commits: - 96e2a7e576 fix(libSceAjm): check batch job buffer counts before the 8-bit cast - 9b20e4eb70 test(libSceAjm): refuse batch job buffer counts that wrap past 32 bits ### Tested - Host: Linux, archive build, lane 1, on the final head (rebased onto current `main`). - `ctest -R '^guest_ajm$'`: 1 of 1 passed (`guest_ajm`, Test #2204). - `tools/check_conventions.py --base upstream/main` and `git diff --check upstream/main`: clean. ### Not verified - Negative control (old code, new test) not run. - The refusal code (`INVALID_PARAMETER`) follows the existing range check; the console value is not measured. - The Vorbis byte-rate overflow found in the same audit is not in this PR; it overlaps open #15021 and will be a follow-up. ### Checklist - [x] Based on current `main`; no other open PR changes this check - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except technical debt - [x] Depends on: none - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
XairRrR commented 2026-11-03 15:22:49 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by XairRrR on 2026-11-03T15:22:49Z.

Review: APPROVED


Reviewed — approved

The new guard in sceAjmBatchJobRunSplit checks the size_t buffer counts before they are narrowed. This stops counts such as 2^32 + 1 from wrapping to a small valid value. The new test catches the bug on main.

What I ran

  • Head 9b20e4eb70ceafbba4921cd6d776e54f7f91f236 merged with --no-ff into main 4f41f4c375f5abb487dbd184fbc150f31994d762 (merged tree 94ecc44b8c349ffa6a6d8b4b45849d566ec13200).
  • Machine: Debian 13 VM, 32 vCPU (2× Intel Xeon Gold 6136), GCC 14.2.0, Release, Ninja.
git diff --check 4f41f4c375f5abb487dbd184fbc150f31994d762...9b20e4eb70ceafbba4921cd6d776e54f7f91f236
python3 tools/check_conventions.py --base 4f41f4c375f5abb487dbd184fbc150f31994d762
ctest --test-dir build -R '^guest_ajm$' --output-on-failure
# negative control
git show 4f41f4c375f5abb487dbd184fbc150f31994d762:core/libs/prx/libSceAjm.native/src/Ajm.cpp > core/libs/prx/libSceAjm.native/src/Ajm.cpp
ninja -C build -j32 -l32 libs guest_ajm_tests
ctest --test-dir build -R '^guest_ajm$' --output-on-failure
# restore
git show 94ecc44b8c349ffa6a6d8b4b45849d566ec13200:core/libs/prx/libSceAjm.native/src/Ajm.cpp > core/libs/prx/libSceAjm.native/src/Ajm.cpp
ninja -C build -j32 -l32 libs guest_ajm_tests
ctest --test-dir build -R '^guest_ajm$'
git status --porcelain

Results

Check Result
git diff --check clean
check_conventions.py All conventions checks passed
Configure / build / libs (script) ok
Selected tests (script) 800 ran, 798 passed, 1 expected skip; no new failures, no timeouts
Known failure unwrap_self_UnwrapTest_test_new_output_inherits_the_destination_directory_group: it also fails on main and is not related to this PR
guest_ajm (merged tree) passed (0.08 s)
guest_ajm with Ajm.cpp from main aborted (Subprocess aborted)
guest_ajm after restoring the merged file passed; git status --porcelain empty
Vulkan validation comparison skipped (no AGC, shader or VideoOut file changed)

Negative control

I put only core/libs/prx/libSceAjm.native/src/Ajm.cpp back to main, kept the PR's test and rebuilt. guest_ajm then aborted. With the merged file restored, it passes. This confirms the Windows results that bunbeans2-arch and BunnyFl reported, now on Linux/GCC 14.

Findings

Blocking

None.

Non-blocking

  • The 0xff refusal differs from the console and is not recorded as debt. I checked BunnyFl's point:

    • JobRejected refuses counts above 0xff because of the host's 8-bit packed job.
    • docs/dev/debt/libSceAjm.native.md has no entry for this limit.
    • The new guard (core/libs/prx/libSceAjm.native/src/Ajm.cpp:2067) extends the same refusal to counts above 32 bits. Per BunnyFl's disassembly of 13.42, the console returns 0x80930012 in that case when the sideband is valid.

    The PR returns a refusal where main silently ran a wrong job, so this is a strict improvement. The divergence itself is older than this PR. Suggested follow-up: add a debt entry for the host's 255-buffer limit and its error code, and add a test row with an 8-byte sideband to pin the intended code.

Not verified

  • Console behaviour: I did not run anything on hardware. The console comparison above relies on BunnyFl's disassembly.
  • Windows: not run here. Two other commenters reported Windows runs.
<!-- greyfinch-sync:boykopovar/AnyPS5:review:5754807867 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/15321#pullrequestreview-5754807867). Originally posted by [XairRrR](https://github.com/XairRrR) on 2026-11-03T15:22:49Z. **Review:** APPROVED --- # Reviewed — approved The new guard in `sceAjmBatchJobRunSplit` checks the `size_t` buffer counts before they are narrowed. This stops counts such as `2^32 + 1` from wrapping to a small valid value. The new test catches the bug on `main`. ## What I ran - Head `9b20e4eb70ceafbba4921cd6d776e54f7f91f236` merged with `--no-ff` into `main` `4f41f4c375f5abb487dbd184fbc150f31994d762` (merged tree `94ecc44b8c349ffa6a6d8b4b45849d566ec13200`). - Machine: Debian 13 VM, 32 vCPU (2× Intel Xeon Gold 6136), GCC 14.2.0, Release, Ninja. ```sh git diff --check 4f41f4c375f5abb487dbd184fbc150f31994d762...9b20e4eb70ceafbba4921cd6d776e54f7f91f236 python3 tools/check_conventions.py --base 4f41f4c375f5abb487dbd184fbc150f31994d762 ctest --test-dir build -R '^guest_ajm$' --output-on-failure # negative control git show 4f41f4c375f5abb487dbd184fbc150f31994d762:core/libs/prx/libSceAjm.native/src/Ajm.cpp > core/libs/prx/libSceAjm.native/src/Ajm.cpp ninja -C build -j32 -l32 libs guest_ajm_tests ctest --test-dir build -R '^guest_ajm$' --output-on-failure # restore git show 94ecc44b8c349ffa6a6d8b4b45849d566ec13200:core/libs/prx/libSceAjm.native/src/Ajm.cpp > core/libs/prx/libSceAjm.native/src/Ajm.cpp ninja -C build -j32 -l32 libs guest_ajm_tests ctest --test-dir build -R '^guest_ajm$' git status --porcelain ``` ## Results | Check | Result | |---|---| | `git diff --check` | clean | | `check_conventions.py` | All conventions checks passed | | Configure / build / `libs` (script) | ok | | Selected tests (script) | 800 ran, 798 passed, 1 expected skip; no new failures, no timeouts | | Known failure | `unwrap_self_UnwrapTest_test_new_output_inherits_the_destination_directory_group`: it also fails on `main` and is not related to this PR | | `guest_ajm` (merged tree) | passed (0.08 s) | | `guest_ajm` with `Ajm.cpp` from `main` | aborted (Subprocess aborted) | | `guest_ajm` after restoring the merged file | passed; `git status --porcelain` empty | | Vulkan validation comparison | skipped (no AGC, shader or VideoOut file changed) | ## Negative control I put only `core/libs/prx/libSceAjm.native/src/Ajm.cpp` back to `main`, kept the PR's test and rebuilt. `guest_ajm` then aborted. With the merged file restored, it passes. This confirms the Windows results that bunbeans2-arch and BunnyFl reported, now on Linux/GCC 14. ## Findings ### Blocking None. ### Non-blocking - **The 0xff refusal differs from the console and is not recorded as debt.** I checked BunnyFl's point: - [`JobRejected`](https://github.com/boykopovar/AnyPS5/blob/9b20e4eb70ceafbba4921cd6d776e54f7f91f236/core/libs/prx/libSceAjm.native/src/Ajm.cpp#L237-L239) refuses counts above `0xff` because of the host's 8-bit packed job. - `docs/dev/debt/libSceAjm.native.md` has no entry for this limit. - The new guard (`core/libs/prx/libSceAjm.native/src/Ajm.cpp:2067`) extends the same refusal to counts above 32 bits. Per BunnyFl's disassembly of 13.42, the console returns `0x80930012` in that case when the sideband is valid. The PR returns a refusal where `main` silently ran a wrong job, so this is a strict improvement. The divergence itself is older than this PR. Suggested follow-up: add a debt entry for the host's 255-buffer limit and its error code, and add a test row with an 8-byte sideband to pin the intended code. ## Not verified - Console behaviour: I did not run anything on hardware. The console comparison above relies on BunnyFl's disassembly. - Windows: not run here. Two other commenters reported Windows runs. <!-- anyps5-bots job=2892 head=9b20e4eb70ceafbba4921cd6d776e54f7f91f236 -->
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!15321
No description provided.