Skip to content

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

Closed
nicolasabosch wants to merge 1 commit into
boykopovar:mainfrom
nicolasabosch:fix/relinker-preserve-input
Closed

nicolasabosch wants to merge 1 commit into
boykopovar:mainfrom
nicolasabosch:fix/relinker-preserve-input

Conversation

@nicolasabosch

Copy link
Copy Markdown
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

build needs rebase Conflicts with main, rebase needed relinker

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant