fix(relinker): reject outputs that overwrite the input file #356

Closed
nicolasabosch wants to merge 1 commit from upstream-pr/356 into main
nicolasabosch commented 2026-10-02 12:21:41 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by nicolasabosch on 2026-10-02T12:21:41Z.


What

The relinker can overwrite its source ELF when the output identifies the input file. For example, relinker --skip-sce-module --windows input.elf input.elf currently succeeds and replaces the original ELF with a PE executable.

Reject that output using C++20 std::filesystem::equivalent before conversion or artifact writes. Distinct output files, including existing files, remain valid. Add and register a real-binary regression test covering identical paths, relative/absolute and normalized aliases, hard links, symlinks when supported, and case aliases on case-insensitive Windows filesystems. Both Linux ELF and Windows PE output modes are covered; rejection preserves input bytes and creates no registry artifact.

Tested

  • Windows x64, MSVC 19.51.36257, C++20 Release, Ninja, Python 3.13. Synthetic ELF fixtures; no commercial game files.
  • Built the relinker and all tests registered by core/relinker/CMakeLists.txt using a temporary CMake harness outside the repository. The harness sets C++20, enables testing, defines the root add_test_executable helper, and adds the unchanged relinker subdirectory. The full runtime/library build and the documented MinGW toolchain were not tested locally.
  • Reproduced successful input overwrite on unpatched main. The new test fails against that binary and passes with the guard.
  • ctest --test-dir work/relinker-build --output-on-failure: 16/16 passed. Hard-link, symlink and Windows case-alias cases ran without skips.
  • git diff --check: passed.

Checklist

  • Based on current main; no other open PR implements the same functions (95 open PRs checked)
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt (no new comments)
  • Unimplemented paths throw; silent stubs are listed in TechnicalDebt (no new unimplemented paths or stubs)
  • No notes, investigation .md files or images added to the repository
  • New third-party code is a submodule built from source (no new third-party code)
  • Generic behaviour, not specific to one title
  • Depends on: none
  • AI-assisted: yes, written and tested with OpenAI Codex
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4716341245 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/356). Originally posted by [nicolasabosch](https://github.com/nicolasabosch) on 2026-10-02T12:21:41Z. --- ### What The relinker can overwrite its source ELF when the output identifies the input file. For example, `relinker --skip-sce-module --windows input.elf input.elf` currently succeeds and replaces the original ELF with a PE executable. Reject that output using C++20 `std::filesystem::equivalent` before conversion or artifact writes. Distinct output files, including existing files, remain valid. Add and register a real-binary regression test covering identical paths, relative/absolute and normalized aliases, hard links, symlinks when supported, and case aliases on case-insensitive Windows filesystems. Both Linux ELF and Windows PE output modes are covered; rejection preserves input bytes and creates no registry artifact. ### Tested - Windows x64, MSVC 19.51.36257, C++20 Release, Ninja, Python 3.13. Synthetic ELF fixtures; no commercial game files. - Built the relinker and all tests registered by `core/relinker/CMakeLists.txt` using a temporary CMake harness outside the repository. The harness sets C++20, enables testing, defines the root `add_test_executable` helper, and adds the unchanged relinker subdirectory. The full runtime/library build and the documented MinGW toolchain were not tested locally. - Reproduced successful input overwrite on unpatched main. The new test fails against that binary and passes with the guard. - `ctest --test-dir work/relinker-build --output-on-failure`: **16/16 passed**. Hard-link, symlink and Windows case-alias cases ran without skips. - `git diff --check`: passed. ### Checklist - [x] Based on current `main`; no other open PR implements the same functions (95 open PRs checked) - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except technical debt (no new comments) - [x] Unimplemented paths throw; silent stubs are listed in TechnicalDebt (no new unimplemented paths or stubs) - [x] No notes, investigation `.md` files or images added to the repository - [x] New third-party code is a submodule built from source (no new third-party code) - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] AI-assisted: yes, written and tested with OpenAI Codex

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