fix(relinker): reject non-regular input files #2294

Merged
Vabian124 merged 1 commit from upstream-pr/2294 into main 2026-10-10 06:35:30 +00:00
Vabian124 commented 2026-10-09 14:53:08 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Vabian124 on 2026-10-09T14:53:08Z.


What

FileReader::Read rejects a path that is not a regular file before it sizes the input buffer from ifstream::tellg. A directory can open, and tellg can report an enormous size, so the relinker tried to allocate that size and threw std::bad_alloc. A negative size now throws Cannot read file before the buffer is allocated.

This change was written with AI assistance. The pull request author is responsible for every line.

Tested

Windows 10 (10.0.26200), PowerShell. WinLibs MinGW-w64 GCC 15.2.0 (x86_64-ucrt-posix-seh, release 15.2.0posix-14.0.0-ucrt-r7), CMake 4.3.1, Ninja 1.13.2, Python 3.12.

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
ctest --test-dir build-relinker -R "^input_file$" --output-on-failure --timeout 120
ctest --test-dir build-relinker --output-on-failure --timeout 120

input_file passed. The relinker-only ctest passed, 41/41.

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; silent stubs are listed in TechnicalDebt
  • No notes, investigation .md files or images added to the repository
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4802075715 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2294). Originally posted by [Vabian124](https://github.com/Vabian124) on 2026-10-09T14:53:08Z. --- ### What `FileReader::Read` rejects a path that is not a regular file before it sizes the input buffer from `ifstream::tellg`. A directory can open, and `tellg` can report an enormous size, so the relinker tried to allocate that size and threw `std::bad_alloc`. A negative size now throws `Cannot read file` before the buffer is allocated. This change was written with AI assistance. The pull request author is responsible for every line. ### Tested Windows 10 (10.0.26200), PowerShell. WinLibs MinGW-w64 GCC 15.2.0 (x86_64-ucrt-posix-seh, release 15.2.0posix-14.0.0-ucrt-r7), CMake 4.3.1, Ninja 1.13.2, Python 3.12. ``` 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 ctest --test-dir build-relinker -R "^input_file$" --output-on-failure --timeout 120 ctest --test-dir build-relinker --output-on-failure --timeout 120 ``` `input_file` passed. The relinker-only ctest passed, 41/41. ### 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; silent stubs are listed in TechnicalDebt - [x] No notes, investigation `.md` files or images added to the repository - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] AI-assisted: yes
AnzouBelilita commented 2026-10-09 15:15:26 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by AnzouBelilita on 2026-10-09T15:15:26Z.


Independent Windows validation on PR #2294:

  • OS: Windows 10 Pro, build 19045
  • Toolchain: MinGW-w64 GCC 16.2.0, CMake 4.4.4, Ninja 1.13.2
  • Fresh relinker-only configuration and build completed successfully (155 build steps).
  • Full relinker-only CTest suite: 41/41 passed, 0 failures.
  • The focused input_file test passed.
  • python tools/check_conventions.py --base upstream/main passed.
  • git diff --check upstream/main...review/pr2294 passed.

The test was run against PR head d40bcf2b6b26e698e6d573ac695a6c52d3ce9353, based on upstream main d70b89989473ba1f6ae13e44e079e67f1f8a44b0.

This provides an independent Windows validation of the change. No production code was modified by this validation.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6083750803 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2294#issuecomment-6083750803). Originally posted by [AnzouBelilita](https://github.com/AnzouBelilita) on 2026-10-09T15:15:26Z. --- Independent Windows validation on PR #2294: * OS: Windows 10 Pro, build 19045 * Toolchain: MinGW-w64 GCC 16.2.0, CMake 4.4.4, Ninja 1.13.2 * Fresh relinker-only configuration and build completed successfully (155 build steps). * Full relinker-only CTest suite: **41/41 passed**, 0 failures. * The focused `input_file` test passed. * `python tools/check_conventions.py --base upstream/main` passed. * `git diff --check upstream/main...review/pr2294` passed. The test was run against PR head `d40bcf2b6b26e698e6d573ac695a6c52d3ce9353`, based on upstream main `d70b89989473ba1f6ae13e44e079e67f1f8a44b0`. This provides an independent Windows validation of the change. No production code was modified by this validation.
oneandonlydean commented 2026-10-10 05:18:27 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-10T05:18:27Z.


Conflicts with main in core/relinker/CMakeLists.txt; please rebase.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6094142011 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2294#issuecomment-6094142011). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-10T05:18:27Z. --- Conflicts with main in `core/relinker/CMakeLists.txt`; please rebase.
adriadam10 commented 2026-10-10 06:32:11 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-10T06:32:11Z.


Rebased onto current main (only conflict: adjacent add_test lines in core/relinker/CMakeLists.txt next to input_preservation; both kept). Relinker build and ctest green, including input_file. Merging once CI is green.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6094681880 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2294#issuecomment-6094681880). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-10T06:32:11Z. --- Rebased onto current `main` (only conflict: adjacent `add_test` lines in `core/relinker/CMakeLists.txt` next to `input_preservation`; both kept). Relinker build and ctest green, including `input_file`. 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!2294
No description provided.