fix(relinker): preserve input binaries when writing registries #3495

Merged
Lorkydey merged 1 commit from upstream-pr/3495 into main 2026-10-11 11:56:53 +00:00
Lorkydey commented 2026-10-11 11:40:31 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Lorkydey on 2026-10-11T11:40:31Z.


What

Prevent --registry from overwriting the input executable or an input guest module when a generated registry path names the same file, including through hard links or symbolic links.

For example, converting an ELF named output.registry.json to output.exe with --windows --skip-sce-module --registry currently succeeds but replaces the input ELF with a 6-byte JSON report. The relinker now rejects the collision before writing any registry or converted binary. All registry destinations are checked first, so a collision in a later module registry also leaves existing reports and outputs untouched.

Guest artifacts retain their source paths for the checks. The existing input-preservation test covers both executable and module registries, both input types, direct names and linked aliases, and Windows/Linux output formats. No Markdown files or dependencies are changed.

Tested

Windows x64, WinLibs MinGW-w64 GCC 15.2.0 (ucrt r7), CMake/Ninja, Release, BUILD_TESTING=ON, based on main 0f863c10:

  • The new regression test fails against main's relinker: it returns success and overwrites the source. It passes after the fix.
  • cmake --build build --parallel 8: passed.
  • ctest --test-dir build/core/relinker --output-on-failure --parallel 4 --no-tests=error: 95/95 passed.
  • Standalone conversions with --skip-sce-module: collisions preserve the source and return exit 2; existing unrelated registries can still be replaced successfully, for both output formats.
  • python tools/check_conventions.py --base origin/main and git diff --check origin/main...HEAD: passed.

Linux outputs were generated and inspected on Windows; no native Linux or macOS runtime testing was performed 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 (NotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt
  • 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 (no new dependencies)
  • Generic behaviour, not specific to one title
  • Depends on: none
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4818782710 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3495). Originally posted by [Lorkydey](https://github.com/Lorkydey) on 2026-10-11T11:40:31Z. --- ### What Prevent `--registry` from overwriting the input executable or an input guest module when a generated registry path names the same file, including through hard links or symbolic links. For example, converting an ELF named `output.registry.json` to `output.exe` with `--windows --skip-sce-module --registry` currently succeeds but replaces the input ELF with a 6-byte JSON report. The relinker now rejects the collision before writing any registry or converted binary. All registry destinations are checked first, so a collision in a later module registry also leaves existing reports and outputs untouched. Guest artifacts retain their source paths for the checks. The existing input-preservation test covers both executable and module registries, both input types, direct names and linked aliases, and Windows/Linux output formats. No Markdown files or dependencies are changed. ### Tested Windows x64, WinLibs MinGW-w64 GCC 15.2.0 (ucrt r7), CMake/Ninja, Release, BUILD_TESTING=ON, based on main `0f863c10`: - The new regression test fails against main's relinker: it returns success and overwrites the source. It passes after the fix. - `cmake --build build --parallel 8`: passed. - `ctest --test-dir build/core/relinker --output-on-failure --parallel 4 --no-tests=error`: 95/95 passed. - Standalone conversions with `--skip-sce-module`: collisions preserve the source and return exit 2; existing unrelated registries can still be replaced successfully, for both output formats. - `python tools/check_conventions.py --base origin/main` and `git diff --check origin/main...HEAD`: passed. Linux outputs were generated and inspected on Windows; no native Linux or macOS runtime testing was performed 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](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed in [TechnicalDebt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/TechnicalDebt.md#silent-stubs) - [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 (no new dependencies) - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] AI-assisted: yes
adriadam10 commented 2026-10-11 11:56:50 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-11T11:56:50Z.


Checked: all registry paths are validated against the input executable and input modules (direct, hardlink, symlink) before anything is written; the regression test fails without the change and passes with it; relinker ctest scope green on Linux. Merging once CI is green.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6108766276 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3495#issuecomment-6108766276). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-11T11:56:50Z. --- Checked: all registry paths are validated against the input executable and input modules (direct, hardlink, symlink) before anything is written; the regression test fails without the change and passes with it; relinker ctest scope green on Linux. Merging once CI is green.
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!3495
No description provided.