fix(relinker): protect executable inputs from output overwrites #2243

Merged
NumberGuan merged 2 commits from upstream-pr/2243 into main 2026-10-10 04:45:47 +00:00
NumberGuan commented 2026-10-09 12:55:47 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by NumberGuan on 2026-10-09T12:55:47Z.


What

The relinker can overwrite its input executable or a bundled input module when the executable output refers to the same file, including through a hard link. Conversion reports success.

Reject these destinations before writing the registry, converted modules or executable. The main-input check also runs with --skip-sce-module; the module check uses the input inventory discovered by GuestModuleBuilder. Separate existing output files remain replaceable. Add an integration regression and document the output constraint.

This complements #2100, which protects the JSON registry destination. The module guard runs after the input inventory is finalized and combines cleanly with #2212's module discovery changes, verified with git merge-tree. There is no functional dependency.

Tested

Windows x64, WinLibs MinGW-w64 GCC 15.2.0 UCRT POSIX SEH r7, Ninja Release, Python 3.12.14. Based on upstream d70b8998; current contribution a406ad4d.

cmake -S . -B build-relinker -G Ninja -DCMAKE_BUILD_TYPE=Release -DANYPS5_RELINKER_ONLY=ON -DBUILD_TESTING=ON
cmake --build build-relinker --parallel 4
ctest --test-dir build-relinker --output-on-failure --timeout 120 --no-tests=error --parallel 2
python tools/check_test_registration.py build-relinker
python tools/check_conventions.py --base origin/main
git diff origin/main --check

All 41 registered test groups passed on the initial dc9c75b5 head. After moving the module guard on a406ad4d, the relinker rebuilt and four focused groups passed: input_preservation, guest_module_directories, guest_needed_modules and guest_host_libc. Registration, conventions and whitespace checks passed. tls_function_coverage took 68.99 seconds in the initial full run; no repository timeout was changed.

The new regression fails on the original implementation, which converts over its input executable and returns success. With only the main-input guard applied, it then fails on conversion over a bundled input module. The complete fix passes both.

The regression checks Linux ELF and Windows PE conversion on the Windows host: direct paths, normalized paths, hard links, unchanged source bytes, error status and diagnostic, and absence of generated outputs on rejection. Valid new and existing destinations still convert. Four symbolic-link cases were skipped because this session cannot create symbolic links.

GitHub Actions passed Conventions and the relinker build/test matrix on Windows, Linux and macOS for the current a406ad4d head: Build run, Conventions run. The full Linux and Windows build jobs were skipped under the repository's pull-request policy. System-library builds and game/PS5 tests were not run locally.

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; no silent stubs added
  • No notes, investigation files or images added to the repository
  • New third-party code is a submodule built from source; none added
  • Generic behaviour, not specific to one title
  • Depends on: none
  • AI-assisted: yes, Codex
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4800698959 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2243). Originally posted by [NumberGuan](https://github.com/NumberGuan) on 2026-10-09T12:55:47Z. --- ### What The relinker can overwrite its input executable or a bundled input module when the executable output refers to the same file, including through a hard link. Conversion reports success. Reject these destinations before writing the registry, converted modules or executable. The main-input check also runs with `--skip-sce-module`; the module check uses the input inventory discovered by `GuestModuleBuilder`. Separate existing output files remain replaceable. Add an integration regression and document the output constraint. This complements #2100, which protects the JSON registry destination. The module guard runs after the input inventory is finalized and combines cleanly with #2212's module discovery changes, verified with `git merge-tree`. There is no functional dependency. ### Tested Windows x64, WinLibs MinGW-w64 GCC 15.2.0 UCRT POSIX SEH r7, Ninja Release, Python 3.12.14. Based on upstream `d70b8998`; current contribution `a406ad4d`. ```text cmake -S . -B build-relinker -G Ninja -DCMAKE_BUILD_TYPE=Release -DANYPS5_RELINKER_ONLY=ON -DBUILD_TESTING=ON cmake --build build-relinker --parallel 4 ctest --test-dir build-relinker --output-on-failure --timeout 120 --no-tests=error --parallel 2 python tools/check_test_registration.py build-relinker python tools/check_conventions.py --base origin/main git diff origin/main --check ``` All 41 registered test groups passed on the initial `dc9c75b5` head. After moving the module guard on `a406ad4d`, the relinker rebuilt and four focused groups passed: `input_preservation`, `guest_module_directories`, `guest_needed_modules` and `guest_host_libc`. Registration, conventions and whitespace checks passed. `tls_function_coverage` took 68.99 seconds in the initial full run; no repository timeout was changed. The new regression fails on the original implementation, which converts over its input executable and returns success. With only the main-input guard applied, it then fails on conversion over a bundled input module. The complete fix passes both. The regression checks Linux ELF and Windows PE conversion on the Windows host: direct paths, normalized paths, hard links, unchanged source bytes, error status and diagnostic, and absence of generated outputs on rejection. Valid new and existing destinations still convert. Four symbolic-link cases were skipped because this session cannot create symbolic links. GitHub Actions passed Conventions and the relinker build/test matrix on Windows, Linux and macOS for the current `a406ad4d` head: [Build run](https://github.com/boykopovar/AnyPS5/actions/runs/37938385010), [Conventions run](https://github.com/boykopovar/AnyPS5/actions/runs/37938388730). The full Linux and Windows build jobs were skipped under the repository's pull-request policy. System-library builds and game/PS5 tests were not run locally. ### 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 - [x] Unimplemented paths throw; no silent stubs added - [x] No notes, investigation files or images added to the repository - [x] New third-party code is a submodule built from source; none added - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] AI-assisted: yes, Codex
github-actions[bot] commented 2026-10-09 15:29:03 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-09T15:29:03Z.


Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.

Pull request Conflicting files (lines on main) Same exports Same new files
#2294 core/relinker/CMakeLists.txt L269
#2545 core/relinker/relinker/tests/test_input_preservation.py
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6083984196 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2243#issuecomment-6083984196). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-09T15:29:03Z. --- <!-- pr-overlap --> Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in **Depends on**. | Pull request | Conflicting files (lines on `main`) | Same exports | Same new files | |---|---|---|---| | #2294 | `core/relinker/CMakeLists.txt` [L269](https://github.com/boykopovar/AnyPS5/blob/698254f048952385120dba5b7af7658be2fd49e6/core/relinker/CMakeLists.txt#L269) | | | | #2545 | | | `core/relinker/relinker/tests/test_input_preservation.py` |
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!2243
No description provided.