fix(relinker): reject large non-ELF inputs before allocation #8689
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/8689"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-20T21:07:01Z.
What
Preflight the input with the existing ELF header parser using a bounded 64-byte read before
FileReader::Readallocates a vector for the full file. Unsupported large files now fail with the existing format-specific diagnostic instead ofstd::bad_alloc; short ELF inputs and SELF/bad-magic diagnostics continue through the same parser. The full read and all later ELF handling are unchanged.Fixes #8685
Unblocks: none
GPUs tested: n/a
Tested
Debian GNU/Linux 13, x86-64, GCC 12.2.0, Ninja, Release,
ANYPS5_RELINKER_ONLY=ON,BUILD_TESTING=ON.input_magicregression creates an 8 GiB sparse non-ELF file and limits the child relinker to 512 MiB of address space. A pre-fix local binary fromb5d55bd804fails withFAIL: std::bad_alloc; this branch exits 2 withInvalid ELF magic number: 7f 46 49 48and creates no output.python3 tools/check_conventions.py --base origin/main,git diff --check origin/main...HEAD, andpython3 tools/pr_overlap.py --branch codex/reject-large-non-elf-earlypass; the overlap check reports no open-PR overlap.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by Filip722 on 2026-10-21T09:14:01Z.
Confirmed the allocation and early-rejection fix for my report #8685 on
11adccfe15258e21e9ba6e90b947f674320ad9a8. I rebuilt this revision on Debian 13 x86-64 (GCC 15.2, Release, relinker-only) and compared it with the original reported binary ata6a4101e1.FAIL: std::bad_allocto exit 2 withFAIL: Invalid ELF magic number: 7f 46 49 48.--skip-sce-module. Invalid input is rejected before the missing-module diagnostic on the default CLI path, and no output file is created.input_magicandelf_header.This confirms the reported allocation/validation-order bug is fixed. The error text still only names the invalid magic; explicit guidance to supply an extracted clean ELF and its bundled modules, as requested in the issue, would remain a useful diagnostic improvement. No title execution was tested.
AI-assisted verification.
Imported from boykopovar/AnyPS5. Originally posted by cadenasynyster on 2026-10-21T17:54:29Z.
Independent Windows run of this PR.
Environment: Windows 11 10.0.26300 (NTFS), Ryzen 7 9800X3D, WinLibs GCC 15.2.0 r7 UCRT, Release, BUILD_TESTING=ON, PR head.
Tests:
elf_headerandinput_magicpass. The 8 GiB case intest_input_magic.pyruns only on Linux (RLIMIT_AS), so it is skipped here.Manual probe on Windows: I created a 4 GiB file whose first bytes are
7f 46 49 48(set withFileStream.SetLength) and ranrelinker --windows --skip-sce-module <file> <out>. I then kept the PR's tests and replaced only the five production files (FileReader.hpp/.cpp,main.cpp,ElfReader.hpp/.cpp) with their base versions:Cannot read file: <path>, and no output file is created.Invalid ELF magic number: 7f 46 49 48, and no output file is created.So on this host the base does not show
std::bad_alloc; the user-visible problem is a misleading read error, and the PR replaces it with the format diagnostic.Not run: Linux/macOS, a baseline run of the unit tests, peak memory, the bundled-module scan without
--skip-sce-module, and the full repository CTest.AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-21T19:13:43Z.
Checked the diff against the description:
ValidateMagicis the existing header check moved out ofReadHeaderwith the same messages, andConvertnow runs it on a 64-byte prefix before the full read. The 8 GiB sparse-file test under a 512 MiB address-space cap fails withstd::bad_alloconmainand passes here. Relinker jobs (Linux, Windows, macOS, ASan) are green, and Filip722's and cadenasynyster's runs confirm it on Debian and Windows; merged.Imported from boykopovar/AnyPS5. Originally posted by Iluminatti312 on 2026-10-21T19:16:04Z.
Independent Windows validation — PASS
I independently built and tested this PR on Windows.
Environment
11adccfe1ANYPS5_RELINKER_ONLY=ON,BUILD_TESTING=ONBuild and test results
input_magictest: PASSlong_paths, because WindowsLongPathsEnabledis not enabled.Additional Windows reproduction
I created a 256 MiB NTFS sparse file whose first four bytes were
7f 46 49 48(invalid ELF magic), then executed:Observed:
The invalid large input was rejected with the expected ELF diagnostic, and no output executable was created.
Scope of validation: This confirms compilation, regression tests, and early rejection of a 256 MiB invalid input on Windows. I did not measure peak memory usage or reproduce the original 8 GiB / 512 MiB address-space-limit scenario.
AI-assisted investigation and test preparation; all reported commands and results were executed locally.