fix(tests): destroy the pad input before the pad identify test quits SDL #14438

Merged
xXPBSXx merged 1 commit from upstream-pr/14438 into main 2026-11-02 22:36:23 +00:00
xXPBSXx commented 2026-11-01 13:22:17 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-11-01T13:22:17Z.


What

The nightly sanitizer run of 2026-11-01 (run 41270298089) failed pad_identify_connect, pad_identify_off and pad_identify_rumble with an AddressSanitizer heap-use-after-free in SDL_GameControllerClose (SDL_gamecontroller.c:3036). In Run of PadIdentify.cpp, padInput is a local that lives to the end of the function, but SDL_QuitSubSystem(SDL_INIT_GAMECONTROLLER | SDL_INIT_JOYSTICK) runs before that and frees every controller that is still open; ~PadInput then calls SDL_GameControllerClose on the freed controller. This puts padInput and the checks that use it in their own block, so it is destroyed before the virtual controller is detached and SDL is quit. Only the test changes: the shutdown of the title already does it in this order (VideoOutDriver resets padInput on the present thread before SDL_QuitSubSystem).

Tested

WSL Ubuntu 24.04 with gcc 13.3, Release, ANYPS5_ENABLE_ASAN=ON and -g1. On main e67cc81869 each of the three tests fails in 3 of 3 runs with a heap-use-after-free report at SDL_gamecontroller.c:3036, the same line as in the nightly; the test file is the same at ba627802e2, the base of this branch; with this change each passes 3 of 3 runs with no AddressSanitizer output, and pad_identify_invalid passes. tools/check_conventions.py --base upstream/main passes. Not run: Windows (AddressSanitizer is Linux only), the UndefinedBehaviorSanitizer flags the nightly adds, and the other tests of the repository.

Overlap

I took the changed files of each of the 1661 open pull requests from git diff --name-only against its merge base (listed at 11:56 UTC on 2026-11-01; one ref, #13454, could not be fetched, and its GitHub file list does not show PadIdentify.cpp). None of them changes core/libs/prx/libSceVideoOut/tests/PadIdentify.cpp. git merge-tree against main f1a7b02028 (checked at 13:19 UTC on 2026-11-01): this head merges cleanly. None of the 33 pull requests opened since (#14401 to #14435) changes PadIdentify.cpp.

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

AI-assisted (Claude Code).

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5107736980 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/14438). Originally posted by [xXPBSXx](https://github.com/xXPBSXx) on 2026-11-01T13:22:17Z. --- ### What The nightly sanitizer run of 2026-11-01 (run 41270298089) failed `pad_identify_connect`, `pad_identify_off` and `pad_identify_rumble` with an AddressSanitizer heap-use-after-free in `SDL_GameControllerClose` (`SDL_gamecontroller.c:3036`). In `Run` of `PadIdentify.cpp`, `padInput` is a local that lives to the end of the function, but `SDL_QuitSubSystem(SDL_INIT_GAMECONTROLLER | SDL_INIT_JOYSTICK)` runs before that and frees every controller that is still open; `~PadInput` then calls `SDL_GameControllerClose` on the freed controller. This puts `padInput` and the checks that use it in their own block, so it is destroyed before the virtual controller is detached and SDL is quit. Only the test changes: the shutdown of the title already does it in this order (`VideoOutDriver` resets `padInput` on the present thread before `SDL_QuitSubSystem`). ### Tested WSL Ubuntu 24.04 with gcc 13.3, Release, `ANYPS5_ENABLE_ASAN=ON` and `-g1`. On `main` e67cc81869 each of the three tests fails in 3 of 3 runs with a heap-use-after-free report at `SDL_gamecontroller.c:3036`, the same line as in the nightly; the test file is the same at ba627802e2, the base of this branch; with this change each passes 3 of 3 runs with no AddressSanitizer output, and `pad_identify_invalid` passes. `tools/check_conventions.py --base upstream/main` passes. Not run: Windows (AddressSanitizer is Linux only), the UndefinedBehaviorSanitizer flags the nightly adds, and the other tests of the repository. ### Overlap I took the changed files of each of the 1661 open pull requests from `git diff --name-only` against its merge base (listed at 11:56 UTC on 2026-11-01; one ref, #13454, could not be fetched, and its GitHub file list does not show `PadIdentify.cpp`). None of them changes `core/libs/prx/libSceVideoOut/tests/PadIdentify.cpp`. `git merge-tree` against `main` `f1a7b02028` (checked at 13:19 UTC on 2026-11-01): this head merges cleanly. None of the 33 pull requests opened since (#14401 to #14435) changes `PadIdentify.cpp`. ### Checklist - [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] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes AI-assisted (Claude Code). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
MarcZX10 commented 2026-11-01 13:49:11 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-01T13:49:11Z.

Review: COMMENTED


Reviewed — no blocking findings

Scoping padInput in its own block makes it destroy before the virtual controller is detached and before SDL_QuitSubSystem, which is the ordering the use-after-free report needs; the change is confined to one test file and reads correctly at head 185adf1624.

What I ran

  • Exact head 185adf16249616e4e1e1176d6eb21dfb18c9e0ce, base f1a7b02028 (the PR base).
  • Environment: Linux, /usr/bin/python3 3.11.2, no build.
  • Precheck: python3 tools/pr_precheck.py --repo boykopovar/AnyPS5 --pr 14438 --output-dir /dev/shm/reviewer-run/precheck/14438
  • Head file read with gh api contents at 185adf16: the block closes at line 122, SDL_JoystickDetachVirtual(device) is at line 124, and SDL_QuitSubSystem at line 125.
  • Test-quality helper on the changed test, from a head extract (one literal-path registration heuristic; the file's test target is already registered).

Results

Precheck report, checks table, unedited (/dev/shm/reviewer-run/precheck/14438/report.md):

Check Status Command / reason
build_and_compile not_applicable The precheck deliberately does not configure, build, or compile AnyPS5.
diff_check passed git diff --check f1a7b02028ae50adaf6c5aaaef892a51841b25bf...185adf16249616e4e1e1176d6eb21dfb18c9e0ce
conventions_and_pr_template passed /usr/bin/python3 tools/check_conventions.py --base f1a7b02028ae50adaf6c5aaaef892a51841b25bf --head 185adf16249616e4e1e1176d6eb21dfb18c9e0ce --title fix(tests): destroy the pad input before the pad identify test quits SDL --body /dev/shm/reviewer-run/precheck/14438/pr-body.md
changed_export_abi_audit failed /usr/bin/python3 tools/pr_abi_audit.py --base f1a7b02028ae50adaf6c5aaaef892a51841b25bf --head 185adf16249616e4e1e1176d6eb21dfb18c9e0ce --json
python_syntax not_applicable No changed Python implementation files.
related_python_unit_tests not_applicable No changed tools/ module has an existing sibling tools/tests/test_<module>.py suite.
python_test_registration not_applicable No changed test_*.py files.
live_dependency_and_mergeability_check passed /usr/bin/python3 /marc/AnyPS5/tools/pr_stack_check.py 14438 --repo boykopovar/AnyPS5 --output-dir /dev/shm/reviewer-run/precheck/14438/stack
build_dependent_cpp_tests not_applicable Not run: C++ tests need exact-head binaries, which require a build; the precheck does not build.
test_quality_heuristics failed /usr/bin/python3 /dev/shm/reviewer-run/precheck/14438/head-185adf162496-c9cc4e01/tools/pr_test_quality.py --root /dev/shm/reviewer-run/precheck/14438/head-185adf162496-c9cc4e01 --json core/libs/prx/libSceVideoOut/tests/PadIdentify.cpp
negative_controls not_applicable No changed Python test module in tools/ can be run as a no-build base-source control.

The ABI audit row is not applicable: the change touches no export or header.

Negative control

Not run here. The PR reports that each of the three tests fails with a heap-use-after-free on main, under ASan, in 3 of 3 runs; that is the author's report.

Findings

Blocking: none.

Non-blocking: none.

Sources

Not verified

  • The test was not built or run here. The ASan results before and after the change are the author's.
  • Hosted: every check was queued at review time.
<!-- greyfinch-sync:boykopovar/AnyPS5:review:5728367061 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/14438#pullrequestreview-5728367061). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-01T13:49:11Z. **Review:** COMMENTED --- # Reviewed — no blocking findings Scoping `padInput` in its own block makes it destroy before the virtual controller is detached and before `SDL_QuitSubSystem`, which is the ordering the use-after-free report needs; the change is confined to one test file and reads correctly at head 185adf1624. ## What I ran - Exact head `185adf16249616e4e1e1176d6eb21dfb18c9e0ce`, base `f1a7b02028` (the PR base). - Environment: Linux, `/usr/bin/python3` 3.11.2, no build. - Precheck: `python3 tools/pr_precheck.py --repo boykopovar/AnyPS5 --pr 14438 --output-dir /dev/shm/reviewer-run/precheck/14438` - Head file read with `gh api` contents at `185adf16`: the block closes at line 122, `SDL_JoystickDetachVirtual(device)` is at line 124, and `SDL_QuitSubSystem` at line 125. - Test-quality helper on the changed test, from a head extract (one literal-path registration heuristic; the file's test target is already registered). ## Results Precheck report, checks table, unedited (`/dev/shm/reviewer-run/precheck/14438/report.md`): | Check | Status | Command / reason | |---|---|---| | build_and_compile | not_applicable | `The precheck deliberately does not configure, build, or compile AnyPS5.` | | diff_check | passed | `git diff --check f1a7b02028ae50adaf6c5aaaef892a51841b25bf...185adf16249616e4e1e1176d6eb21dfb18c9e0ce` | | conventions_and_pr_template | passed | `/usr/bin/python3 tools/check_conventions.py --base f1a7b02028ae50adaf6c5aaaef892a51841b25bf --head 185adf16249616e4e1e1176d6eb21dfb18c9e0ce --title fix(tests): destroy the pad input before the pad identify test quits SDL --body /dev/shm/reviewer-run/precheck/14438/pr-body.md` | | changed_export_abi_audit | failed | `/usr/bin/python3 tools/pr_abi_audit.py --base f1a7b02028ae50adaf6c5aaaef892a51841b25bf --head 185adf16249616e4e1e1176d6eb21dfb18c9e0ce --json` | | python_syntax | not_applicable | `No changed Python implementation files.` | | related_python_unit_tests | not_applicable | `No changed tools/ module has an existing sibling tools/tests/test_<module>.py suite.` | | python_test_registration | not_applicable | `No changed test_*.py files.` | | live_dependency_and_mergeability_check | passed | `/usr/bin/python3 /marc/AnyPS5/tools/pr_stack_check.py 14438 --repo boykopovar/AnyPS5 --output-dir /dev/shm/reviewer-run/precheck/14438/stack` | | build_dependent_cpp_tests | not_applicable | `Not run: C++ tests need exact-head binaries, which require a build; the precheck does not build.` | | test_quality_heuristics | failed | `/usr/bin/python3 /dev/shm/reviewer-run/precheck/14438/head-185adf162496-c9cc4e01/tools/pr_test_quality.py --root /dev/shm/reviewer-run/precheck/14438/head-185adf162496-c9cc4e01 --json core/libs/prx/libSceVideoOut/tests/PadIdentify.cpp` | | negative_controls | not_applicable | `No changed Python test module in tools/ can be run as a no-build base-source control.` | The ABI audit row is not applicable: the change touches no export or header. ## Negative control Not run here. The PR reports that each of the three tests fails with a heap-use-after-free on `main`, under ASan, in 3 of 3 runs; that is the author's report. ## Findings **Blocking:** none. **Non-blocking:** none. ## Sources - Head test file, block and quit ordering: https://github.com/boykopovar/AnyPS5/blob/185adf16249616e4e1e1176d6eb21dfb18c9e0ce/core/libs/prx/libSceVideoOut/tests/PadIdentify.cpp#L99-L126 ## Not verified - The test was not built or run here. The ASan results before and after the change are the author's. - Hosted: every check was queued at review time.
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!14438
No description provided.