fix(relinker): normalize additional module directory paths #3509

Merged
Lorkydey merged 1 commit from upstream-pr/3509 into main 2026-10-11 21:29:10 +00:00
Lorkydey commented 2026-10-11 12:04:07 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Lorkydey on 2026-10-11T12:04:07Z.


What

Normalize --module-dir paths before validating and recording them.

  • Compare the first normalized component with .., so valid names such as ..plugins are accepted while parent traversal is rejected.
  • Reject a root name or root directory. On Windows, \outside and C:plugins are not absolute paths, but can reset or qualify the path when joined to the guest root. A root-relative path currently lets a module outside the game directory be converted into an artifact outside app0.
  • Remove the trailing empty component before storing a directory. Media/Plugins/ and Media/Plugins must both retain deferred initialization; previously the trailing separator prevented the directory from matching a module's parent, eagerly initializing it on Windows or adding it to the executable's DT_NEEDED on Linux.

The checks use the C++ filesystem path queries and lexical normalization. Validation is lexical and does not resolve symbolic links. 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, rebased onto current main a11c8f7f:

  • Reproduced the rejection of ..plugins and acceptance of an existing outside directory through a Windows root-relative path before the fix.
  • The new test fails on the previous relinker. An additional lifecycle assertion also fails before stripping the trailing separator.
  • Relinker-only Release configuration: cmake -S . -B build-relinker -G Ninja -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_COMPILER=g++ -DANYPS5_RELINKER_ONLY=ON -DBUILD_TESTING=ON.
  • cmake --build build-relinker --parallel 8: passed.
  • ctest --test-dir build-relinker --output-on-failure --parallel 4 --no-tests=error: 108/108 passed.
  • python tools/check_test_registration.py build-relinker: passed.
  • Integration coverage checks normalized output paths, preserved input modules, deferred initialization metadata for PE and ELF, rejection without producing output, and execution of the Windows fixtures (exit 42).
  • python tools/check_conventions.py --base origin/main and git diff --check origin/main...HEAD: passed.

Linux files 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:4818910702 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3509). Originally posted by [Lorkydey](https://github.com/Lorkydey) on 2026-10-11T12:04:07Z. --- ### What Normalize `--module-dir` paths before validating and recording them. - Compare the first normalized component with `..`, so valid names such as `..plugins` are accepted while parent traversal is rejected. - Reject a root name or root directory. On Windows, `\outside` and `C:plugins` are not absolute paths, but can reset or qualify the path when joined to the guest root. A root-relative path currently lets a module outside the game directory be converted into an artifact outside `app0`. - Remove the trailing empty component before storing a directory. `Media/Plugins/` and `Media/Plugins` must both retain deferred initialization; previously the trailing separator prevented the directory from matching a module's parent, eagerly initializing it on Windows or adding it to the executable's `DT_NEEDED` on Linux. The checks use the C++ filesystem [path queries](https://eel.is/c++draft/fs.path.query) and [lexical normalization](https://eel.is/c++draft/fs.path.gen). Validation is lexical and does not resolve symbolic links. 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, rebased onto current main `a11c8f7f`: - Reproduced the rejection of `..plugins` and acceptance of an existing outside directory through a Windows root-relative path before the fix. - The new test fails on the previous relinker. An additional lifecycle assertion also fails before stripping the trailing separator. - Relinker-only Release configuration: `cmake -S . -B build-relinker -G Ninja -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_COMPILER=g++ -DANYPS5_RELINKER_ONLY=ON -DBUILD_TESTING=ON`. - `cmake --build build-relinker --parallel 8`: passed. - `ctest --test-dir build-relinker --output-on-failure --parallel 4 --no-tests=error`: 108/108 passed. - `python tools/check_test_registration.py build-relinker`: passed. - Integration coverage checks normalized output paths, preserved input modules, deferred initialization metadata for PE and ELF, rejection without producing output, and execution of the Windows fixtures (exit 42). - `python tools/check_conventions.py --base origin/main` and `git diff --check origin/main...HEAD`: passed. Linux files 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 21:29:06 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-11T21:29:06Z.


Checked the normalization in GuestModuleBuilder.cpp (..plugins accepted, parent traversal / root names / root directories rejected, trailing separator stripped), relinker build + ctest (101/101), and that guest_module_dir fails without the change. Merging.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6113977381 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3509#issuecomment-6113977381). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-11T21:29:06Z. --- Checked the normalization in `GuestModuleBuilder.cpp` (`..plugins` accepted, parent traversal / root names / root directories rejected, trailing separator stripped), relinker build + ctest (101/101), and that `guest_module_dir` fails without the change. Merging.
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!3509
No description provided.