fix(libSceAudioOut): avoid partial output write in sceAudioOut2UserGetSupportedAttributes #25046

Merged
gurtgg merged 1 commit from upstream-pr/25046 into main 2026-11-21 16:40:59 +00:00
gurtgg commented 2026-11-21 15:50:44 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by gurtgg on 2026-11-21T15:50:44Z.


What

  • Fix partial output write in sceAudioOut2UserGetSupportedAttributes (core/libs/prx/libSceAudioOut/src/AudioOut2User.cpp), which previously overwrote *contextAttributes via CopyUserOutput_nid_no_patch before failing to write an unwritable non-null portAttributes pointer and returning 0x80268001.
  • Add CopyUserInput_nid_no_patch wrapping GuestCopyIn_nid_no_patch with errno save/restore; when both contextAttributes and portAttributes are non-null, snapshot *contextAttributes before writing context and restore the saved value if writing portAttributes fails, preserving host errno.
  • Record the resolved partial-write behavior in docs/dev/debt/changes/audioout2-user-atomic-attr-outputs.md (high-reach PRX audio library libSceAudioOut / libSceAudioOut2).

Tested

  • CheckUserSupportedAttributes (core/libs/prx/libSceAudioOut/tests/AudioOut2AmbisonicsEncode.cpp): verifies that an unwritable portAttributes leaves contextAttr == 0xdeadbeefu unchanged (overwritten to 0 before fix) and preserves errno == 71 while returning 0x80268001, verifies unwritable contextAttributes leaves portAttr == 0xcafebabeu unchanged and errno == 71, and checks valid output values (contextAttr == 0, portAttr == 3).

Checklist

  • tools/check_conventions.py rules verified (UTF-8 no-BOM LF, zero disallowed comments, Conventional Commits)
  • Negative-control regression test fails against unmodified main and passes after fix
  • AI-assisted: yes
  • Depends on: none
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5429629336 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/25046). Originally posted by [gurtgg](https://github.com/gurtgg) on 2026-11-21T15:50:44Z. --- ### What - Fix partial output write in `sceAudioOut2UserGetSupportedAttributes` (`core/libs/prx/libSceAudioOut/src/AudioOut2User.cpp`), which previously overwrote `*contextAttributes` via `CopyUserOutput_nid_no_patch` before failing to write an unwritable non-null `portAttributes` pointer and returning `0x80268001`. - Add `CopyUserInput_nid_no_patch` wrapping `GuestCopyIn_nid_no_patch` with `errno` save/restore; when both `contextAttributes` and `portAttributes` are non-null, snapshot `*contextAttributes` before writing `context` and restore the saved value if writing `portAttributes` fails, preserving host `errno`. - Record the resolved partial-write behavior in `docs/dev/debt/changes/audioout2-user-atomic-attr-outputs.md` (high-reach PRX audio library `libSceAudioOut` / `libSceAudioOut2`). ### Tested - `CheckUserSupportedAttributes` (`core/libs/prx/libSceAudioOut/tests/AudioOut2AmbisonicsEncode.cpp`): verifies that an unwritable `portAttributes` leaves `contextAttr == 0xdeadbeefu` unchanged (overwritten to `0` before fix) and preserves `errno == 71` while returning `0x80268001`, verifies unwritable `contextAttributes` leaves `portAttr == 0xcafebabeu` unchanged and `errno == 71`, and checks valid output values (`contextAttr == 0`, `portAttr == 3`). ### Checklist - [x] `tools/check_conventions.py` rules verified (UTF-8 no-BOM LF, zero disallowed comments, Conventional Commits) - [x] Negative-control regression test fails against unmodified `main` and passes after fix - AI-assisted: yes - Depends on: none
PrivacyOnion commented 2026-11-21 16:05:15 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-21T16:05:15Z.

Review: APPROVED


Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against 5b5bda4fcc:

  • Conventions: tools/check_conventions.py passed.
  • Build: audio_out2_ambisonics_encode_tests built cleanly.
  • CTest (audio_out2_ambisonics_encode):
    1/1 Test #3690: audio_out2_ambisonics_encode .....   Passed    0.01 sec
    100% tests passed, 0 tests failed out of 1
    
  • Negative control: with core/libs/prx/libSceAudioOut/src/AudioOut2User.cpp reverted to main and the new tests kept, the suite fails:
    1/1 Test #3690: audio_out2_ambisonics_encode .....Subprocess aborted***Exception:   1.87 sec
    0% tests passed, 1 tests failed out of 1
    
    Restoring the change makes it pass again.
  • Code reading:
    • Verified core/libs/prx/libSceAudioOut/src/AudioOut2User.cpp:sceAudioOut2UserGetSupportedAttributes checks handle valid range and non-null pointers in order (0x80268010 on invalid handle, 0x80268001 when both pointers null)
    • Verified GuestCopyIn_nid_no_patch / GuestCopyOut_nid_no_patch wrapper CopyUserInput_nid_no_patch preserves errno and safely catches faulting pointers without segfaults
    • Verified g_usersLock mutex acquisition and release: lock_guard held across map lookup and output writes, avoiding race conditions
    • Verified rollback semantics: contextAttributes is snapshotted via CopyUserInput_nid_no_patch only when both pointers are non-null and restored on portAttributes copy failure, preventing partial caller-memory mutation
    • Verified technical debt fragment docs/dev/debt/changes/audioout2-user-atomic-attr-outputs.md follows standard fragment syntax and documents unmeasured behavior
    • Verified test coverage in core/libs/prx/libSceAudioOut/tests/AudioOut2AmbisonicsEncode.cpp properly creates a user, checks error codes, tests unwritable pointers, asserts preserved errno and deadbeef memory, and cleans up handle via sceAudioOut2UserDestroy

Looks Good To Me

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6006443039 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/25046#pullrequestreview-6006443039). Originally posted by [PrivacyOnion](https://github.com/PrivacyOnion) on 2026-11-21T16:05:15Z. **Review:** APPROVED --- Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against `5b5bda4fcc`: - **Conventions**: `tools/check_conventions.py` passed. - **Build**: `audio_out2_ambisonics_encode_tests` built cleanly. - **CTest** (`audio_out2_ambisonics_encode`): ``` 1/1 Test #3690: audio_out2_ambisonics_encode ..... Passed 0.01 sec 100% tests passed, 0 tests failed out of 1 ``` - **Negative control**: with `core/libs/prx/libSceAudioOut/src/AudioOut2User.cpp` reverted to `main` and the new tests kept, the suite fails: ``` 1/1 Test #3690: audio_out2_ambisonics_encode .....Subprocess aborted***Exception: 1.87 sec 0% tests passed, 1 tests failed out of 1 ``` Restoring the change makes it pass again. - **Code reading**: - Verified core/libs/prx/libSceAudioOut/src/AudioOut2User.cpp:sceAudioOut2UserGetSupportedAttributes checks handle valid range and non-null pointers in order (0x80268010 on invalid handle, 0x80268001 when both pointers null) - Verified GuestCopyIn_nid_no_patch / GuestCopyOut_nid_no_patch wrapper CopyUserInput_nid_no_patch preserves errno and safely catches faulting pointers without segfaults - Verified g_usersLock mutex acquisition and release: lock_guard held across map lookup and output writes, avoiding race conditions - Verified rollback semantics: contextAttributes is snapshotted via CopyUserInput_nid_no_patch only when both pointers are non-null and restored on portAttributes copy failure, preventing partial caller-memory mutation - Verified technical debt fragment docs/dev/debt/changes/audioout2-user-atomic-attr-outputs.md follows standard fragment syntax and documents unmeasured behavior - Verified test coverage in core/libs/prx/libSceAudioOut/tests/AudioOut2AmbisonicsEncode.cpp properly creates a user, checks error codes, tests unwritable pointers, asserts preserved errno and deadbeef memory, and cleans up handle via sceAudioOut2UserDestroy Looks Good To Me
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!25046
No description provided.