Skip to content

fix(tools): reject invalid COFF inline name padding - #14331

Merged
oneandonlydean merged 2 commits into
boykopovar:mainfrom
DonRyuzaki:fix/tools-coff-inline-names
Nov 6, 2026
Merged

oneandonlydean merged 2 commits into
boykopovar:mainfrom
DonRyuzaki:fix/tools-coff-inline-names

Conversation

@DonRyuzaki

@DonRyuzaki DonRyuzaki commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

What

Reject inline COFF symbol names with nonzero bytes after their first NUL, following the Microsoft PE/COFF ShortName padding contract. A malformed name rejects the whole module for symbolization, so all of that module’s frames remain unsymbolized. Previously junk became part of the sampled symbol name. Exactly eight-byte names and correctly NUL-padded UTF-8 names remain supported.

The regression inputs are synthetic malformed COFF fixtures; no real-title reproduction was performed for this change. Nonzero bytes after the first NUL violate the inline ShortName padding contract, so the tool rejects that module and preserves its frames rather than inventing a symbol name.

Tested

Windows, Python 3.12: full symbolize_samples suite, 40 tests (39 passed, 1 platform skip). Three malformed-padding regression cases fail on main. Valid eight-byte and padded UTF-8 controls pass. check_conventions.py --base origin/main and git diff --check pass. Official pr_overlap.py comparison of 1,602 open PR heads reports no overlap (public REST snapshot transport; unchanged comparison logic with exact-base probe caching).

Base: 26fa121. Published c4e2ad6 has the tested local tree 2d71c8737f11ef5ae47632e3e94bcf9a8b095030. No runtime/game test claim.

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 under Silent stubs in their library's technical debt file
  • 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
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes

@MarcZX10 MarcZX10 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed — no blocking findings

The change rejects inline COFF short names with nonzero bytes after their first NUL, and the three malformed-padding cases fail on base, so the new check is exercised; I found no blocking issue, only two non-blocking notes.

What I ran

Exact head f276d27a7d67b17156b86c982a72f419eb276705, base 26fa1212b82f76dd49cf12d65e445d6ff3e0844c (current main). The merge preview against that base is clean.

Environment: Debian GNU/Linux 12 host, Python from the precheck interpreter /marc/Conlyse-VIEJO/.venv/bin/python3. No project build and no C++ compile or CTest run. The Python unit suite ran on Linux (the author's Windows run is not repeated here).

python3 tools/pr_precheck.py --repo boykopovar/AnyPS5 --pr 14331
python3 -I tools/pr_test_quality.py --root <git archive of f276d27a7d67, tools/ only> --json tools/symbolize_samples.py tools/tests/test_symbolize_samples.py

The precheck's test-quality step failed only because the helper is absent from the head tree. I ran the same helper by hand on an archive of the head's tools/ files; it reported zero findings.

Results

Check Result
git diff --check against base passed
conventions and PR template passed
py_compile tools/symbolize_samples.py passed
python -m unittest tools.tests.test_symbolize_samples passed, 40 tests, 2 skipped on Linux
test registration (check_test_registration.py --scripts) passed
merge preview against current base (pr_stack_check.py) clean
test-quality heuristic, run by hand 0 findings
hosted CI at review time eligibility, conventions, intake and labels queued; not complete
Unedited unittest output (precheck, Linux)
..................................s...s.
----------------------------------------------------------------------
Ran 40 tests in 0.972s

OK (skipped=2)

Negative control

Assertion Change to the code under test New test failed?
test_coff_short_names_reject_nonzero_bytes_after_the_terminator (three padding cases) Base code (name.rstrip(b"\0")) Yes: three failures, ValueError not raised

The valid controls in test_coff_full_width_and_padded_utf8_names_remain_supported pass on the head.

Findings

Blocking: none.

Non-blocking:

  1. Failure granularity. A bad name on an emitted code symbol makes PeModule raise for the whole module. The callers catch that and leave every frame of that module unsymbolized (symbolize_samples.py L193-L195 at the head). That matches the file's other COFF checks, so I am not asking for a change. The PR body should say that the rejection is per module, not per symbol, so a reader does not expect one bad name to be skipped.
  2. Test name. test_coff_full_width_and_padded_utf8_names_remain_supported does not test a full-width character. It covers a name that fills all eight bytes (café plus abc) and a NUL-padded café. A name such as ..._exact_eight_bytes_and_padded_utf8_names_remain_supported would match what it checks.

Sources

  • Head implementation:
    else:
    text, terminator, padding = name.partition(b"\0")
    if terminator and padding.strip(b"\0"):
    raise ValueError("COFF short name has nonzero padding after its terminator")
  • Caller fallback:
    module = PeModule(path)
    except (OSError, ValueError, struct.error) as error:
    self.warn(f"{name}: {error}")
  • New test:
    def test_coff_short_names_reject_nonzero_bytes_after_the_terminator(self):
    path = self.libs / "libSceAgcDriver.prx"
    original = path.read_bytes()
    table = struct.unpack_from("<I", original, 0x4C)[0]
    for name in (b"f\0X\0\0\0\0\0", b"func\0X\0\0", b"name12\0X"):
    with self.subTest(name=name):
    data = bytearray(original)
    data[table + 2 * 18:table + 2 * 18 + 8] = name
    path.write_bytes(data)
    with self.assertRaisesRegex(ValueError, "COFF short name"):

The padding rule itself comes from the PR body's citation of the Microsoft PE/COFF ShortName contract. I did not re-read that specification here.

Not verified

  • The Windows unit run cited in the PR body was not repeated.
  • The PE/COFF specification wording was not re-checked.
  • No game, runtime, or console behaviour was tested, and none is claimed.
  • Hosted CI jobs were still queued when reviewed.

@MarcZX10 MarcZX10 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-checked — same head, looks good

The exact reviewed head remains f276d27a7d67b17156b86c982a72f419eb276705; the new COFF padding validation and its registered Python tests have no blocking findings.

What I ran

The earlier exact-head review ran tools/pr_precheck.py, Python syntax validation, the 40-test tools.tests.test_symbolize_samples suite (40 passed, 2 skipped on Linux), test registration checks, and the test-quality heuristic. No project build or C++ compile was run. The hosted Ubuntu and Windows relinker checks and ASan check have since passed; two macOS relinker jobs remain pending and do not exercise the changed Python tool.

python3 tools/pr_precheck.py --repo boykopovar/AnyPS5 --pr 14331
python3 -m unittest tools.tests.test_symbolize_samples
python3 tools/check_test_registration.py --scripts

Results

Check Result
Python unit tests 40 passed, 2 skipped on Linux
Conventions and registration Passed
Hosted Ubuntu/Windows relinker and ASan Passed
Hosted macOS relinker jobs Pending; unrelated to changed Python tool

Not verified

The author's Windows Python run is not independently repeated here. No game, runtime, or console behavior was tested.

@MarcZX10 MarcZX10 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed — no blocking findings; a COFF short name with bytes after its terminator is now rejected, and the Ubuntu symbolize test passed

This PR makes tools/symbolize_samples.py reject a COFF inline symbol name when the bytes after its first NUL are not all zero. The old code stripped trailing NULs and kept whatever came before; the new code splits at the first NUL and checks the rest. The Ubuntu relinker job ran the tool's test file as CTest symbolize_samples, and it passed. I read the production change in full.

What I ran

  • Head c4e2ad6ffd777ffcc7b8f2e6be7f41d1dcefb40b; base 26fa1212b82f76dd49cf12d65e445d6ff3e0844c. 2 files, +26/-1: tools/symbolize_samples.py (+3/-1) and tools/tests/test_symbolize_samples.py (+23).
  • Read the production change in full. text, terminator, padding = name.partition(b"\0"). If a terminator exists and padding has any non-NUL byte, the function raises ValueError. A name with no NUL is unchanged.
  • Test file: read the added method names only; test bodies not read.
  • Hosted: the Ubuntu relinker job's CTest symbolize_samples (Test #167) passed in a run of 554 of 554. The macOS clang, macOS x86_64, Ubuntu and Windows relinkers and relinker-asan succeeded. Windows check-run skipped.
  • Read-only checks from the trusted main checkout: diff check and conventions passed. ABI audit not applicable. Stack check: clean, no declared dependencies, no errors.
  • No MarcZX10 review at this head.

Results

Check Result Note
Diff check passed
Conventions and PR template passed the latest run succeeded; an earlier run was cancelled
Mergeability and dependencies passed stack check: clean; no declared dependencies
ABI audit not applicable no export changed
symbolize_samples (hosted, Ubuntu relinker job) passed Test #167
Relinkers and relinker-asan (hosted) passed all succeeded
Production change (read) passed by reading the partition and the padding check are as described; no blocking defect found
Test bodies in test_symbolize_samples.py not verified names only
Negative controls not run no local build; no PR-head Python runs here
Read-only check output

Precheck was not run: no PR-head code is run here. Diff check: passed. Conventions: passed. ABI audit: not applicable. Stack check: clean, no declared dependencies, no errors. Hosted: gh api repos/boykopovar/AnyPS5/commits/c4e2ad6ffd777ffcc7b8f2e6be7f41d1dcefb40b/check-runs, and the Ubuntu relinker job log (554 of 554).

Negative control

Not run here. A negative control needs a local run of the symbolizer tests on a crafted COFF name, and no PR-head Python runs on this machine.

Findings

Blocking

None from the code read.

Non-blocking

  • The old code stripped every trailing NUL, and the new code rejects non-NUL bytes after the first NUL. A real COFF file that puts junk after a terminator would now fail the whole symbolization run rather than be read. The PR does not say whether any real input is affected. That was not checked here.

Sources

Not verified

  • The test bodies in test_symbolize_samples.py.
  • Whether any real COFF input has bytes after the terminator.

To get this to a good state

  • Nothing blocking. Say in the PR body whether a real input can have bytes after the terminator, and what the tool should do then.

@oneandonlydean oneandonlydean self-assigned this Nov 5, 2026
@oneandonlydean
oneandonlydean merged commit a098b3a into boykopovar:main Nov 6, 2026
15 of 16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants