fix(agc): read RELEASE_MEM's INT_SEL only for RELEASE_MEM packets #2338

Closed
LeandroLP23 wants to merge 1 commit from upstream-pr/2338 into main
LeandroLP23 commented 2026-10-09 15:51:31 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by LeandroLP23 on 2026-10-09T15:51:31Z.


What

#1362 reads INT_SEL from packet[2] before it checks that the packet is a RELEASE_MEM (opcode 0x49). preparePacketMemory runs for every PM4 packet, so packets shorter than three dwords are read past their end. Release builds don't show it, but it is undefined behaviour, and builds with _GLIBCXX_ASSERTIONS abort on the std::span bounds check. GCC 15 turns those assertions on in every unoptimized build, so a Debug build also aborts.

This PR reads packet[2] only for RELEASE_MEM. For RELEASE_MEM packets the result is the same as before.

Tested

Windows 11, AMD Radeon 860M, MinGW GCC 15.2. Clean build with -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_FLAGS=-D_GLIBCXX_ASSERTIONS:

agc_driver agc_driver_pm4
main d70b8998 aborts: std::span::operator[] assertion in Driver::preparePacketMemory aborts, same place
this PR passes passes

Bisecting with that build points to b25c6cce, the merge commit of #1362: its parent d026063a passes.

A normal Release build passes both tests before and after the change. Fork CI (Release, Linux and Windows): green (run).

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 in TechnicalDebt
  • 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
  • AI-assisted: yes (Claude Code)
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4802733312 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2338). Originally posted by [LeandroLP23](https://github.com/LeandroLP23) on 2026-10-09T15:51:31Z. --- ### What #1362 reads `INT_SEL` from `packet[2]` before it checks that the packet is a `RELEASE_MEM` (opcode `0x49`). `preparePacketMemory` runs for every PM4 packet, so packets shorter than three dwords are read past their end. Release builds don't show it, but it is undefined behaviour, and builds with `_GLIBCXX_ASSERTIONS` abort on the `std::span` bounds check. GCC 15 turns those assertions on in every unoptimized build, so a Debug build also aborts. This PR reads `packet[2]` only for `RELEASE_MEM`. For `RELEASE_MEM` packets the result is the same as before. ### Tested Windows 11, AMD Radeon 860M, MinGW GCC 15.2. Clean build with `-DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_FLAGS=-D_GLIBCXX_ASSERTIONS`: | | `agc_driver` | `agc_driver_pm4` | |---|---|---| | `main` d70b8998 | aborts: `std::span::operator[]` assertion in `Driver::preparePacketMemory` | aborts, same place | | this PR | passes | passes | Bisecting with that build points to b25c6cce, the merge commit of #1362: its parent d026063a passes. A normal Release build passes both tests before and after the change. Fork CI (Release, Linux and Windows): green ([run](https://github.com/LeandroLP23/AnyPS5/actions/runs/37950873010)). ### 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 in [TechnicalDebt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/TechnicalDebt.md#silent-stubs) - [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] AI-assisted: yes (Claude Code)
Kikoarl commented 2026-10-09 17:32:44 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Kikoarl on 2026-10-09T17:32:44Z.


Linux run: Linux 7.2 (x86_64), GCC 16.2.1, Release, -DBUILD_TESTING=ON, #2338 (39c4d55a) tested on current main (0fdda7be).

  • tests/agc_driver_pm4_tests: passes cleanly (PM4 catalog, registers, state, memory, conditional execution and submission tests passed).
  • tools/check_conventions.py: passes cleanly.
  • Confirms clean PM4 packet bounds checking on Linux.
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6085976323 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2338#issuecomment-6085976323). Originally posted by [Kikoarl](https://github.com/Kikoarl) on 2026-10-09T17:32:44Z. --- Linux run: Linux 7.2 (x86_64), GCC 16.2.1, Release, `-DBUILD_TESTING=ON`, #2338 (`39c4d55a`) tested on current `main` (`0fdda7be`). - `tests/agc_driver_pm4_tests`: passes cleanly (`PM4 catalog, registers, state, memory, conditional execution and submission tests passed`). - `tools/check_conventions.py`: passes cleanly. - Confirms clean PM4 packet bounds checking on Linux.
Dextroid17 commented 2026-10-09 19:08:38 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Dextroid17 on 2026-10-09T19:08:38Z.

Review: COMMENTED


Heads-up: this is an exact duplicate of #1587 (fix(libSceAgcDriver): read the RELEASE_MEM interrupt select only from RELEASE_MEM packets, krishnaraya4, opened 2026-10-08), which is also open and CLEAN.

Both produce the identical blob for PacketMemory.cpp:

21da6d27f50ca4ae656d8843a99a164af47bcb60

so the two make the same change hunk for hunk ((packet[2] >> 24u) & 7u moved behind an opcode == 0x49 guard). The pr-overlap bot will not flag it: it compares open PRs pairwise by merging their trees and reports only files git flags as conflicting — two PRs making the identical edit to the identical lines merge with no conflict, so it reports nothing.

Only one can merge; worth resolving before a second review is spent on the same two lines.

Written with AI assistance.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5474288614 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2338#pullrequestreview-5474288614). Originally posted by [Dextroid17](https://github.com/Dextroid17) on 2026-10-09T19:08:38Z. **Review:** COMMENTED --- Heads-up: this is an **exact duplicate** of #1587 (`fix(libSceAgcDriver): read the RELEASE_MEM interrupt select only from RELEASE_MEM packets`, krishnaraya4, opened 2026-10-08), which is also open and `CLEAN`. Both produce the identical blob for `PacketMemory.cpp`: ``` 21da6d27f50ca4ae656d8843a99a164af47bcb60 ``` so the two make the same change hunk for hunk (`(packet[2] >> 24u) & 7u` moved behind an `opcode == 0x49` guard). The `pr-overlap` bot will not flag it: it compares open PRs pairwise by merging their trees and reports only files git flags as conflicting — two PRs making the identical edit to the identical lines merge with no conflict, so it reports nothing. Only one can merge; worth resolving before a second review is spent on the same two lines. Written with AI assistance.
LeandroLP23 commented 2026-10-09 19:41:05 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by LeandroLP23 on 2026-10-09T19:41:05Z.


Closing as a duplicate of #1587, which makes the same change and was opened first. Thanks @Dextroid17 for catching it; I missed #1587 when checking for overlaps. My test results are posted there.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6087998214 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2338#issuecomment-6087998214). Originally posted by [LeandroLP23](https://github.com/LeandroLP23) on 2026-10-09T19:41:05Z. --- Closing as a duplicate of #1587, which makes the same change and was opened first. Thanks @Dextroid17 for catching it; I missed #1587 when checking for overlaps. My test results are posted there.

Pull request closed

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!2338
No description provided.