fix(libSceAjm.native): reject ATRAC9 config data with a reserved channel configuration #5658

Merged
wachi35676 merged 1 commit from upstream-pr/5658 into main 2026-10-15 11:55:34 +00:00
wachi35676 commented 2026-10-14 04:55:58 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by wachi35676 on 2026-10-14T04:55:58Z.


What

LibAtrac9 reads the channel configuration of ATRAC9 config data as a 3-bit index (0-7) but ChannelConfigs has six entries (3rdparty/LibAtrac9/C/src/tables.c:9), and ReadConfigData (decinit.c:70) only checks the 0xFE header and the validation bit. Indices 6 and 7 therefore read past the table at decinit.c:47 and initialise a decoder from the bytes that follow; in a local build FE 8C 0B E0 was accepted with 0 channels. A bounds-checked build (-fsanitize=bounds -fsanitize-trap=bounds) traps on that line.

As in #2395, the build now applies the change to a generated copy of decinit.c in PatchLibAtrac9.cmake, leaving the pinned submodule untouched: the config data check also fails for ChannelConfigIndex > 5. The patch stops configuration with FATAL_ERROR if the upstream guard changes. sceAjmDecAt9ParseConfigData, AJM initialization, libSceAudiodec and NGS2 all link the same atrac9 target and already report a failed config as invalid config data, so no PS5-facing code changes. FFmpeg rejects the same values (libavcodec/atrac9dec.c: block_config_idx > 5 → "Incorrect block config!").

New test atrac9_config_data checks all 16 sample-rate indices × 8 channel indices: channel counts 1, 2, 2, 6, 8, 4 for indices 0-5 and rejection for 6 and 7.

Tested

Windows 11 26200, WinLibs GCC 15.2.0 UCRT, full build with BUILD_TESTING=ON on main 75690a117.

  • With the pristine decinit.c compiled into the atrac9 target: atrac9_config_data fails.
  • With this change: atrac9_config_data, atrac9_gradient and guest_ajm pass.
  • Standalone: the unpatched LibAtrac9 sources built with -fsanitize=bounds -fsanitize-trap=bounds trap at decinit.c:47 for indices 6 and 7; with the patched copy they return an error and the test exits 0.
  • python tools/check_conventions.py --base origin/main passes.

Not tested: Linux and macOS builds; titles (no title is known to ship such config data — this is a bounds fix for invalid input, like #2395).

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
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4853159052 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5658). Originally posted by [wachi35676](https://github.com/wachi35676) on 2026-10-14T04:55:58Z. --- ### What LibAtrac9 reads the channel configuration of ATRAC9 config data as a 3-bit index (0-7) but `ChannelConfigs` has six entries (`3rdparty/LibAtrac9/C/src/tables.c:9`), and `ReadConfigData` (`decinit.c:70`) only checks the 0xFE header and the validation bit. Indices 6 and 7 therefore read past the table at `decinit.c:47` and initialise a decoder from the bytes that follow; in a local build `FE 8C 0B E0` was accepted with 0 channels. A bounds-checked build (`-fsanitize=bounds -fsanitize-trap=bounds`) traps on that line. As in #2395, the build now applies the change to a generated copy of `decinit.c` in `PatchLibAtrac9.cmake`, leaving the pinned submodule untouched: the config data check also fails for `ChannelConfigIndex > 5`. The patch stops configuration with `FATAL_ERROR` if the upstream guard changes. `sceAjmDecAt9ParseConfigData`, AJM initialization, libSceAudiodec and NGS2 all link the same `atrac9` target and already report a failed config as invalid config data, so no PS5-facing code changes. FFmpeg rejects the same values (`libavcodec/atrac9dec.c`: `block_config_idx > 5` → "Incorrect block config!"). New test `atrac9_config_data` checks all 16 sample-rate indices × 8 channel indices: channel counts 1, 2, 2, 6, 8, 4 for indices 0-5 and rejection for 6 and 7. ### Tested Windows 11 26200, WinLibs GCC 15.2.0 UCRT, full build with `BUILD_TESTING=ON` on `main` `75690a117`. - With the pristine `decinit.c` compiled into the `atrac9` target: `atrac9_config_data` fails. - With this change: `atrac9_config_data`, `atrac9_gradient` and `guest_ajm` pass. - Standalone: the unpatched LibAtrac9 sources built with `-fsanitize=bounds -fsanitize-trap=bounds` trap at `decinit.c:47` for indices 6 and 7; with the patched copy they return an error and the test exits 0. - `python tools/check_conventions.py --base origin/main` passes. Not tested: Linux and macOS builds; titles (no title is known to ship such config data — this is a bounds fix for invalid input, like #2395). ### 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] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
adriadam10 commented 2026-10-15 11:37:32 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-15T11:37:32Z.


Rebased onto current main (the PatchLibAtrac9.cmake/CMakeLists.txt conflict with the bit_reader.c fast-path patch) and pushed one fix:

  • atrac9_config_data_tests did not link on Linux (undefined reference to sin/pow/sincos, libm missing); added m for non-Windows.

Checked: the PR's test fails with the pristine decinit.c and passes with the patch; atrac9_config_data, atrac9_gradient and guest_ajm pass on Linux. block_config_idx > 5 matches FFmpeg's atrac9dec.c. Merging once CI is green.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6191141823 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5658#issuecomment-6191141823). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-15T11:37:32Z. --- Rebased onto current `main` (the `PatchLibAtrac9.cmake`/`CMakeLists.txt` conflict with the `bit_reader.c` fast-path patch) and pushed one fix: - `atrac9_config_data_tests` did not link on Linux (`undefined reference to sin/pow/sincos`, libm missing); added `m` for non-Windows. Checked: the PR's test fails with the pristine `decinit.c` and passes with the patch; `atrac9_config_data`, `atrac9_gradient` and `guest_ajm` pass on Linux. `block_config_idx > 5` matches FFmpeg's `atrac9dec.c`. Merging once CI is green.
wachi35676 commented 2026-10-15 11:39:03 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by wachi35676 on 2026-10-15T11:39:03Z.


Thanks for rebasing and for the libm fix. I had only built the new test on Windows, where the maths functions come from the C runtime; I'll build new test executables on Linux as well before opening PRs.

AI-assisted: yes (Claude Code).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6191167019 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5658#issuecomment-6191167019). Originally posted by [wachi35676](https://github.com/wachi35676) on 2026-10-15T11:39:03Z. --- Thanks for rebasing and for the libm fix. I had only built the new test on Windows, where the maths functions come from the C runtime; I'll build new test executables on Linux as well before opening PRs. AI-assisted: yes (Claude Code).
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!5658
No description provided.