bug(relinker): large non-ELF inputs allocate the whole file before format validation #8685

Closed
opened 2026-10-20 21:01:41 +00:00 by Filip722 · 1 comment
Filip722 commented 2026-10-20 21:01:41 +00:00 (Migrated from github.com)
Contributor

Imported from boykopovar/AnyPS5. Originally posted by Filip722 on 2026-10-20T21:01:41Z.


Trying to bring up God of War: Sons of Sparta (PPSA28997) from local .pkg files exposed an input-validation problem: the CLI allocates a buffer for the entire input before checking its ELF header. A large unsupported input can therefore report only FAIL: std::bad_alloc, instead of explaining that a clean ELF executable is required.

This report concerns early rejection and diagnostics, not adding package extraction or claiming a title runtime regression. No game code ran.

  • Debian GNU/Linux 13, x86-64.
  • Tested binary: local Linux build at a6a4101e190ec408c3ed471d20f06872cae1b4a3 (existing PR #8640 worktree).
  • Source inspection of upstream main at 9d5099f5e76208ff39d2b3bd70c9d96223c5e353 shows the same full-size allocation in core/relinker/io/src/FileReader.cpp before the header checks in core/relinker/relinker/src/parsing/ElfReader.cpp. Current main was not rebuilt or executed.

Reproduction without game data (Linux, Python 3; pass the relinker binary path as the first argument):

import pathlib
import resource
import subprocess
import sys
import tempfile

relinker = str(pathlib.Path(sys.argv[1]).resolve())

def limit():
    resource.setrlimit(resource.RLIMIT_AS, (512 * 1024**2,) * 2)
    resource.setrlimit(resource.RLIMIT_CORE, (0, 0))

with tempfile.TemporaryDirectory() as directory:
    root = pathlib.Path(directory)
    source = root / "unsupported.pkg"
    for size in (4096, 8 * 1024**3):
        with source.open("wb") as stream:
            stream.write(b"\x7fFIH")
            stream.truncate(size)
        result = subprocess.run(
            [relinker, "--skip-sce-module", str(source), str(root / "out.elf")],
            preexec_fn=limit, capture_output=True, text=True, timeout=15,
        )
        print(size, result.returncode, result.stderr)

Observed:

4096 bytes: exit 2, FAIL: Invalid ELF magic number: 7f 46 49 48
8589934592 bytes: exit 2, FAIL: std::bad_alloc

The larger file is sparse; both inputs have the same invalid magic. The 512 MiB address-space cap is intentional and makes allocation failure deterministic without exhausting host memory. An uncapped out-of-memory failure was not tested. --skip-sce-module is used only to isolate header validation in this reproduction, not as a gameplay workaround.

For the actual local inputs, the 7,762,206,580-byte base package produced FAIL: std::bad_alloc under the same cap. The 1,189,769-byte upgrade package first reported missing sce_module/*.prx; with the diagnostic flag it reported Invalid ELF magic number: 7f 46 49 48. Neither package provided an extracted executable/module layout.

Expected: reject a non-ELF input from a bounded header read before allocating for its entire size or checking bundled modules, and explain that an extracted clean ELF and its bundled modules are required. Valid ELF inputs should retain their existing handling.

Related: closed package-input PR #1056; SELF input questions #173 and #3508. This issue requests bounded rejection of unsupported input rather than reviving package support.

AI-assisted: yes.

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5949594105 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/8685). Originally posted by [Filip722](https://github.com/Filip722) on 2026-10-20T21:01:41Z. --- Trying to bring up God of War: Sons of Sparta (PPSA28997) from local `.pkg` files exposed an input-validation problem: the CLI allocates a buffer for the entire input before checking its ELF header. A large unsupported input can therefore report only `FAIL: std::bad_alloc`, instead of explaining that a clean ELF executable is required. This report concerns early rejection and diagnostics, not adding package extraction or claiming a title runtime regression. No game code ran. - Debian GNU/Linux 13, x86-64. - Tested binary: local Linux build at `a6a4101e190ec408c3ed471d20f06872cae1b4a3` (existing PR #8640 worktree). - Source inspection of upstream main at `9d5099f5e76208ff39d2b3bd70c9d96223c5e353` shows the same full-size allocation in `core/relinker/io/src/FileReader.cpp` before the header checks in `core/relinker/relinker/src/parsing/ElfReader.cpp`. Current main was not rebuilt or executed. Reproduction without game data (Linux, Python 3; pass the relinker binary path as the first argument): ```python import pathlib import resource import subprocess import sys import tempfile relinker = str(pathlib.Path(sys.argv[1]).resolve()) def limit(): resource.setrlimit(resource.RLIMIT_AS, (512 * 1024**2,) * 2) resource.setrlimit(resource.RLIMIT_CORE, (0, 0)) with tempfile.TemporaryDirectory() as directory: root = pathlib.Path(directory) source = root / "unsupported.pkg" for size in (4096, 8 * 1024**3): with source.open("wb") as stream: stream.write(b"\x7fFIH") stream.truncate(size) result = subprocess.run( [relinker, "--skip-sce-module", str(source), str(root / "out.elf")], preexec_fn=limit, capture_output=True, text=True, timeout=15, ) print(size, result.returncode, result.stderr) ``` Observed: ```text 4096 bytes: exit 2, FAIL: Invalid ELF magic number: 7f 46 49 48 8589934592 bytes: exit 2, FAIL: std::bad_alloc ``` The larger file is sparse; both inputs have the same invalid magic. The 512 MiB address-space cap is intentional and makes allocation failure deterministic without exhausting host memory. An uncapped out-of-memory failure was not tested. `--skip-sce-module` is used only to isolate header validation in this reproduction, not as a gameplay workaround. For the actual local inputs, the 7,762,206,580-byte base package produced `FAIL: std::bad_alloc` under the same cap. The 1,189,769-byte upgrade package first reported missing `sce_module/*.prx`; with the diagnostic flag it reported `Invalid ELF magic number: 7f 46 49 48`. Neither package provided an extracted executable/module layout. Expected: reject a non-ELF input from a bounded header read before allocating for its entire size or checking bundled modules, and explain that an extracted clean ELF and its bundled modules are required. Valid ELF inputs should retain their existing handling. Related: closed package-input PR #1056; SELF input questions #173 and #3508. This issue requests bounded rejection of unsupported input rather than reviving package support. AI-assisted: yes.
MarcZX10 commented 2026-10-20 21:40:42 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-20T21:40:42Z.


PR #8689 now addresses this with an early size check before allocating the full non-ELF input. On head 11adccfe15258e21e9ba6e90b947f674320ad9a8, the applicable relinker matrix passed on Linux, Windows, macOS arm64 and x86_64, plus ASan; conventions, eligibility and labels also pass. The full Linux/Windows build jobs are skipped under the repository’s manual-dispatch policy, and the issue remains open until the PR merges.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6302161586 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/8685#issuecomment-6302161586). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-20T21:40:42Z. --- PR #8689 now addresses this with an early size check before allocating the full non-ELF input. On head `11adccfe15258e21e9ba6e90b947f674320ad9a8`, the applicable relinker matrix passed on Linux, Windows, macOS arm64 and x86_64, plus ASan; conventions, eligibility and labels also pass. The full Linux/Windows build jobs are skipped under the repository’s manual-dispatch policy, and the issue remains open until the PR merges.
Sign in to join this conversation.
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#8685
No description provided.