fix(tools): preserve inactive SELF program headers #14534

Merged
Queuse merged 2 commits from upstream-pr/14534 into main 2026-11-02 22:38:54 +00:00
Queuse commented 2026-11-01 15:30:39 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Queuse on 2026-11-01T15:30:39Z.


What

Normalize unused PT_NULL entries before placing decrypted SELF segments. Their undefined offsets must not reject an otherwise valid input or cause unused file bytes to be copied. Active segment bounds and overlap checks remain intact. The ELF gABI defines PT_NULL entries as ignored.

Tested

Head 9145ab72e10543ccd455e3247d4012a6fc20bc42, refreshed against main f2d874c1fdccf781c0fa5d86619bb5dd8894b958.

  • Windows Python 3.12: python -m unittest tools.tests.test_unwrap_self ran 81 tests: 78 passed and 3 existing platform skip(s).
  • Linux WSL, unprivileged user: 81 tests total: 79 passed and 2 existing platform skip(s).
  • Conventions and whitespace checks pass. The current canonical open-PR check reports no overlap.
  • No title, console, full-product or hosted CI result is claimed.

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:5108789843 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/14534). Originally posted by [Queuse](https://github.com/Queuse) on 2026-11-01T15:30:39Z. --- ### What Normalize unused PT_NULL entries before placing decrypted SELF segments. Their undefined offsets must not reject an otherwise valid input or cause unused file bytes to be copied. Active segment bounds and overlap checks remain intact. The [ELF gABI](https://gabi.xinuos.com/elf/07-pheader.html#segment-types) defines PT_NULL entries as ignored. ### Tested Head `9145ab72e10543ccd455e3247d4012a6fc20bc42`, refreshed against main `f2d874c1fdccf781c0fa5d86619bb5dd8894b958`. - Windows Python 3.12: `python -m unittest tools.tests.test_unwrap_self` ran 81 tests: 78 passed and 3 existing platform skip(s). - Linux WSL, unprivileged user: 81 tests total: 79 passed and 2 existing platform skip(s). - Conventions and whitespace checks pass. The current canonical open-PR check reports no overlap. - No title, console, full-product or hosted CI result is claimed. <!-- 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. --> ### 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 -->
BunnyFl commented 2026-11-02 01:16:04 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by BunnyFl on 2026-11-02T01:16:04Z.

Review: APPROVED


Windows 11, Python 3.14.7. Head 9145ab72e1 merged into upstream/main 93dbd0f82a:

  • tools/tests/test_unwrap_self.py: 81 tests OK (5 skipped on this platform).
  • Negative control: with main's tools/unwrap_self.py, test_null_segment_fields_do_not_affect_conversion fails (6 subtest failures).

One effect worth knowing, not a blocker: the normalization mutates headers in place, and the output program header table is written from those dicts (unwrap_self.py ~:396). So PT_NULL entries now come out as all zeros instead of copying the input's fields. The gABI says they're ignored, so that's fine, and the new test pins it.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5731187808 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/14534#pullrequestreview-5731187808). Originally posted by [BunnyFl](https://github.com/BunnyFl) on 2026-11-02T01:16:04Z. **Review:** APPROVED --- Windows 11, Python 3.14.7. Head 9145ab72e1 merged into upstream/main 93dbd0f82a: - `tools/tests/test_unwrap_self.py`: 81 tests OK (5 skipped on this platform). - Negative control: with main's `tools/unwrap_self.py`, `test_null_segment_fields_do_not_affect_conversion` fails (6 subtest failures). One effect worth knowing, not a blocker: the normalization mutates `headers` in place, and the output program header table is written from those dicts (`unwrap_self.py` ~:396). So PT_NULL entries now come out as all zeros instead of copying the input's fields. The gABI says they're ignored, so that's fine, and the new test pins it.
MarcZX10 commented 2026-11-02 05:01:33 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-02T05:01:33Z.

Review: COMMENTED


Reviewed — no blocking findings

place_segments now zeroes the fields of PT_NULL program headers before placement, so stale values in unused slots no longer affect the conversion. The new test sets each field of a PT_NULL slot to all ones and checks that the output does not change; its offsets match the ELF64 Phdr layout (p_flags at 4, p_offset at 8, and so on through p_align at 48). The hosted run has no unwrap_self result for this head, so the test did not run there. One edge in the placement loop is raised below as a question.

What I ran

  • Head 9145ab72e10543ccd455e3247d4012a6fc20bc42; base f2d874c1fdccf781c0fa5d86619bb5dd8894b958. 2 files, +20/-0: tools/unwrap_self.py (+3) and tools/tests/test_unwrap_self.py (+17).
  • Read the full diff, the place_segments function at this head (lines 159-200), and the trailing-segment logic that follows it.
  • Read-only checks from the trusted main checkout (precheck not run; no PR-head Python is run here, per the session rule): diff check and conventions passed.
  • Hosted: no unwrap_self result appears for this head's check runs.
  • No MarcZX10 review at this head.

Results

Check Result Note
Diff check passed
Conventions and PR template passed conventions check from the main checkout
Mergeability and dependencies passed depends on none; the stack check passed
Field offsets in the new test passed match the ELF64 Phdr layout
PT_NULL slots ignored after the change passed read in place_segments (lines 159-164)
Record matching against zeroed PT_NULL headers question a zero-size record can now match a zeroed PT_NULL header (non-blocking)
unwrap_self test (hosted) not run no result for this head
Build and runtime tests not run no Python run here (session rule)
Negative controls not run no Python run here
Hosted CI not complete no unwrap_self result for this head
Read-only check output

Precheck was not run; no PR-head Python is run here. Conventions: passed. Hosted: gh api repos/boykopovar/AnyPS5/commits/9145ab72e10543ccd455e3247d4012a6fc20bc42/check-runs.

Negative control

Not run here. Running the Python tests from this head is not permitted in this session.

Findings

Blocking

None.

Non-blocking

  • In the record-matching loop, headers[target]["size"] == size does not check the header type. A zeroed PT_NULL header has size 0, so a zero-size record that points at it can now set its source and, through the recorded list, become the last header for the trailing placement. Before this change such a header kept its original size. Please confirm that a zero-size record cannot place a PT_NULL header, or exclude PT_NULL in that check.

Sources

Not verified

  • The Python test was not run (session rule: no PR-head code is run here).
  • The record format was not traced beyond the lines quoted.

To get this to a good state

  • Nothing blocking. Confirm the zero-size record path, and add a case if it can happen.
<!-- greyfinch-sync:boykopovar/AnyPS5:review:5732275523 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/14534#pullrequestreview-5732275523). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-02T05:01:33Z. **Review:** COMMENTED --- # Reviewed — no blocking findings `place_segments` now zeroes the fields of `PT_NULL` program headers before placement, so stale values in unused slots no longer affect the conversion. The new test sets each field of a `PT_NULL` slot to all ones and checks that the output does not change; its offsets match the ELF64 `Phdr` layout (`p_flags` at 4, `p_offset` at 8, and so on through `p_align` at 48). The hosted run has no `unwrap_self` result for this head, so the test did not run there. One edge in the placement loop is raised below as a question. ## What I ran - Head `9145ab72e10543ccd455e3247d4012a6fc20bc42`; base `f2d874c1fdccf781c0fa5d86619bb5dd8894b958`. 2 files, +20/-0: `tools/unwrap_self.py` (+3) and `tools/tests/test_unwrap_self.py` (+17). - Read the full diff, the `place_segments` function at this head (lines 159-200), and the trailing-segment logic that follows it. - Read-only checks from the trusted main checkout (precheck not run; no PR-head Python is run here, per the session rule): diff check and conventions passed. - Hosted: no `unwrap_self` result appears for this head's check runs. - No MarcZX10 review at this head. ## Results | Check | Result | Note | | --- | --- | --- | | Diff check | passed | | | Conventions and PR template | passed | conventions check from the main checkout | | Mergeability and dependencies | passed | depends on none; the stack check passed | | Field offsets in the new test | passed | match the ELF64 `Phdr` layout | | `PT_NULL` slots ignored after the change | passed | read in `place_segments` (lines 159-164) | | Record matching against zeroed `PT_NULL` headers | question | a zero-size record can now match a zeroed `PT_NULL` header (non-blocking) | | `unwrap_self` test (hosted) | not run | no result for this head | | Build and runtime tests | not run | no Python run here (session rule) | | Negative controls | not run | no Python run here | | Hosted CI | not complete | no `unwrap_self` result for this head | <details><summary>Read-only check output</summary> Precheck was not run; no PR-head Python is run here. Conventions: passed. Hosted: `gh api repos/boykopovar/AnyPS5/commits/9145ab72e10543ccd455e3247d4012a6fc20bc42/check-runs`. </details> ## Negative control Not run here. Running the Python tests from this head is not permitted in this session. ## Findings **Blocking** None. **Non-blocking** - In the record-matching loop, `headers[target]["size"] == size` does not check the header type. A zeroed `PT_NULL` header has size 0, so a zero-size record that points at it can now set its `source` and, through the `recorded` list, become the `last` header for the trailing placement. Before this change such a header kept its original size. Please confirm that a zero-size record cannot place a `PT_NULL` header, or exclude `PT_NULL` in that check. ## Sources - Changed function: https://github.com/boykopovar/AnyPS5/blob/9145ab72e10543ccd455e3247d4012a6fc20bc42/tools/unwrap_self.py - New test: https://github.com/boykopovar/AnyPS5/blob/9145ab72e10543ccd455e3247d4012a6fc20bc42/tools/tests/test_unwrap_self.py ## Not verified - The Python test was not run (session rule: no PR-head code is run here). - The record format was not traced beyond the lines quoted. ## To get this to a good state - Nothing blocking. Confirm the zero-size record path, and add a case if it can happen.
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!14534
No description provided.