fix(tools): reject dynamic tables without DT_NULL in import_audit #10311

Merged
MarrasFederico merged 1 commit from upstream-pr/10311 into main 2026-10-24 10:40:55 +00:00
MarrasFederico commented 2026-10-23 17:26:30 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarrasFederico on 2026-10-23T17:26:30Z.


What

tools/import_audit.py read an ELF dynamic table until DT_NULL or the end of the table, so a PT_DYNAMIC segment or .dynamic section with no DT_NULL entry was accepted and audited with whatever entries it held. The ELF gABI ends the _DYNAMIC array with DT_NULL, and the relinker rejects such a module: RelativeRelocationIndex.cpp throws Unterminated dynamic segment. An audit could therefore report a module's imports as satisfied although the relinker would refuse the module.

Both readers now fail with AuditError when the table has no DT_NULL: the program-header reader used for modules without section headers (dynamic segment is not terminated by DT_NULL) and the section reader (dynamic section is not terminated by DT_NULL). The command then exits with 2 and writes no JSON report, as for the other malformed inputs. Entries after DT_NULL are still ignored, so padding past the terminator keeps working (#5283 made the dependency walk stop there).

Tested

Ubuntu 26.04.1, Python 3.13, python3 -m unittest test_import_audit in tools/tests. Windows was not run. No title was run.

  • All 135 tests pass on current main (1 skipped, as on main).
  • test_elf_dynamic_tables_require_dt_null replaces the last entry of a section-less module's PT_DYNAMIC and of a sectioned module's .dynamic with a non-null tag: both readers raise, and the command exits with 2, prints the error and leaves no JSON report. It fails with main's import_audit.py.
  • test_sectionless_dynamic_padding_after_dt_null_is_ignored appends a DT_NEEDED-shaped entry after DT_NULL and checks the symbols and dependencies are unchanged.
  • Mutation: not marking the program-header table as terminated fails 13 tests.
  • tools/check_conventions.py --base origin/main passes. tools/pr_overlap.py finds no conflicting lines; it could not compare #6171 and #7454, which conflict with main. Neither changes the dynamic-table loops (they change module identities and $ORIGIN dependency resolution).

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
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4986704246 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10311). Originally posted by [MarrasFederico](https://github.com/MarrasFederico) on 2026-10-23T17:26:30Z. --- ### What `tools/import_audit.py` read an ELF dynamic table until `DT_NULL` or the end of the table, so a `PT_DYNAMIC` segment or `.dynamic` section with no `DT_NULL` entry was accepted and audited with whatever entries it held. The ELF gABI ends the `_DYNAMIC` array with `DT_NULL`, and the relinker rejects such a module: [`RelativeRelocationIndex.cpp`](https://github.com/boykopovar/AnyPS5/blob/4883171f9ffc77ed1fd38a35f1b328125ced23d1/core/relinker/relinker/src/analysis/UnusedNidFilter/RelativeRelocationIndex.cpp#L192-L253) throws `Unterminated dynamic segment`. An audit could therefore report a module's imports as satisfied although the relinker would refuse the module. Both readers now fail with `AuditError` when the table has no `DT_NULL`: the program-header reader used for modules without section headers (`dynamic segment is not terminated by DT_NULL`) and the section reader (`dynamic section is not terminated by DT_NULL`). The command then exits with 2 and writes no JSON report, as for the other malformed inputs. Entries after `DT_NULL` are still ignored, so padding past the terminator keeps working (#5283 made the dependency walk stop there). ### Tested <!-- OS, title or homebrew, what was checked. "Not tested" is a valid answer. A performance change: the summary lines of main and of this PR from the same machine and scene, with the traces attached, captured as the Performance report issue form describes. --> Ubuntu 26.04.1, Python 3.13, `python3 -m unittest test_import_audit` in `tools/tests`. Windows was not run. No title was run. - All 135 tests pass on current `main` (1 skipped, as on `main`). - `test_elf_dynamic_tables_require_dt_null` replaces the last entry of a section-less module's `PT_DYNAMIC` and of a sectioned module's `.dynamic` with a non-null tag: both readers raise, and the command exits with 2, prints the error and leaves no JSON report. It fails with `main`'s `import_audit.py`. - `test_sectionless_dynamic_padding_after_dt_null_is_ignored` appends a `DT_NEEDED`-shaped entry after `DT_NULL` and checks the symbols and dependencies are unchanged. - Mutation: not marking the program-header table as terminated fails 13 tests. - `tools/check_conventions.py --base origin/main` passes. `tools/pr_overlap.py` finds no conflicting lines; it could not compare #6171 and #7454, which conflict with `main`. Neither changes the dynamic-table loops (they change module identities and `$ORIGIN` dependency resolution). ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [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 under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [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 - [x] Generic behaviour, not specific to one title - [x] Depends on: none <!-- #PR, or none --> - [x] Fixes: none <!-- issue it closes as Fixes #N, or none --> - [x] Unblocks: none <!-- title ID and Game bring-up discussion, e.g. PPSA01325 #3232, or none --> - [x] GPUs tested: n/a <!-- for AGC, shader recompiler or VideoOut changes: vendor, model, driver and OS of each GPU the GPU tests ran on; otherwise n/a --> - [x] AI-assisted: yes <!-- yes / no -->
THEMANnt commented 2026-10-24 10:02:21 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by THEMANnt on 2026-10-24T10:02:21Z.

Review: APPROVED


Reviewed head 1723ade7ba5c283544cc44c0209028b1cfa14403 against pinned base aeeaefad98613c63a49ea2daae4d4558304b14cd. No actionable findings in this focused review.

In tools/import_audit.py, elf_program_dynamic_symbols and elf_imports previously accepted dynamic tables that exhausted their declared entries without DT_NULL. Both now raise AuditError unless they encounter the terminator. The checks preserve the existing size validation and stop at the first terminator, so trailing entries remain ignored. I inspected both malformed fixtures, sectionless padding, the existing sectioned terminator test, and error propagation through read_modules and main; parsing errors return 2 before JSON output is written.

Controller-recorded execution of tools/tests/test_import_audit.py used Windows AMD64 and Python 3.11.9. Baseline reported 133 tests with 3 skipped (130 passed); pristine PR and candidate each reported 135 with 3 skipped (132 passed). The baseline-source/candidate-tests negative control failed because the unterminated sectionless table raised no AuditError, confirming the intended old behavior rather than a setup failure. Its first failed assertion prevents the later assertions from running in that control. Local whitespace and conventions checks also succeeded.

GitHub-reported effective checks succeeded for conventions, labels, eligibility, relinker-asan, and the relinker jobs named for Ubuntu/g++, Windows/g++, and both macOS/clang++ variants. linux, windows, write-watch, and register-context were skipped. Workflow identity evidence confirms the older cancelled conventions execution was superseded; no effective execution is failing or pending.

The author's Ubuntu/Python 3.13 results remain author-reported. No local native build, game, or GPU validation was recorded. The inspected source and focused regression evidence support approval.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5637850503 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10311#pullrequestreview-5637850503). Originally posted by [THEMANnt](https://github.com/THEMANnt) on 2026-10-24T10:02:21Z. **Review:** APPROVED --- Reviewed head `1723ade7ba5c283544cc44c0209028b1cfa14403` against pinned base `aeeaefad98613c63a49ea2daae4d4558304b14cd`. No actionable findings in this focused review. In `tools/import_audit.py`, `elf_program_dynamic_symbols` and `elf_imports` previously accepted dynamic tables that exhausted their declared entries without `DT_NULL`. Both now raise `AuditError` unless they encounter the terminator. The checks preserve the existing size validation and stop at the first terminator, so trailing entries remain ignored. I inspected both malformed fixtures, sectionless padding, the existing sectioned terminator test, and error propagation through `read_modules` and `main`; parsing errors return 2 before JSON output is written. Controller-recorded execution of `tools/tests/test_import_audit.py` used Windows AMD64 and Python 3.11.9. Baseline reported 133 tests with 3 skipped (130 passed); pristine PR and candidate each reported 135 with 3 skipped (132 passed). The baseline-source/candidate-tests negative control failed because the unterminated sectionless table raised no `AuditError`, confirming the intended old behavior rather than a setup failure. Its first failed assertion prevents the later assertions from running in that control. Local whitespace and conventions checks also succeeded. GitHub-reported effective checks succeeded for `conventions`, `labels`, `eligibility`, `relinker-asan`, and the relinker jobs named for Ubuntu/g++, Windows/g++, and both macOS/clang++ variants. `linux`, `windows`, `write-watch`, and `register-context` were skipped. Workflow identity evidence confirms the older cancelled conventions execution was superseded; no effective execution is failing or pending. The author's Ubuntu/Python 3.13 results remain author-reported. No local native build, game, or GPU validation was recorded. The inspected source and focused regression evidence support approval. <!-- qwen-review-desk:f13172b5fdd955b7635b574f1f27f7e11df1570cb2e4632e8432b5a81d09d55e -->
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!10311
No description provided.