fix(tools): validate the timeline body when resuming its sequence #11885

Closed
rooklz wants to merge 1 commit from upstream-pr/11885 into main
rooklz commented 2026-10-27 11:33:25 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by rooklz on 2026-10-27T11:33:25Z.


What

previous_sequence in tools/pad_input.py validated only the header of an APS5_PAD_TIMELINE command, while Pad::InputCommandFile::read() (core/libs/prx/libScePad/include/InputCommandFile.hpp) accepts or rejects the whole file: every event row (token count, +-prefixed unsigned values, button mask ⊆ 0x10fffe|0x200000|0x400000, duration 1–5000, ordered non-overlapping events, start ≤ 3600000 − duration, line ≤ 127 chars) and the whitespace-only tail.

A hand-edited command file with a valid header and an invalid body therefore reported a sequence the runtime never adopted:

  • the helpers normally skip past it, which is merely wasteful, but
  • with a header sequence of 18446744073709551615 and any rejected row, both pad_input.py and pad_timeline.py refuse every further command with "controller command sequence is exhausted" until the file is deleted — even though the runtime rejected that command and would adopt a fresh one.

The single-pulse branch of previous_sequence already mirrored its consumer exactly; the timeline body mirror was missing. previous_sequence now validates the timeline body with the same acceptance rules as read(): each of the count rows must be three unsigned tokens ≤ 2⁶⁴−1 within the 127-char line budget, with the consumer's mask, duration, ordering and one-hour checks, and only whitespace may follow. A header whose body is rejected contributes no sequence, so the helpers resume from their own clock, and the exhaustion lockout above no longer triggers.

Tested

macOS 26.2, Apple M5 (arm64), CMake/Ninja, ANYPS5_RELINKER_ONLY=ON, BUILD_TESTING=ON (Python 3.13). Base: 8ff4baf534 (upstream/main), tested head: fa895b282e.

Differential check on this Mac against the real consumer: InputCommandFile.hpp compiled with a driver printing lastSequence after the constructor's first read, compared with pad_input.previous_sequence over

  • 252 commands generated by compile_timeline/pad_input.py (event counts, repeats, gaps, every button combination incl. touch bits and stick forms) — all accepted by the consumer with the exact expected sequence, and
  • 85 adversarial files (count mismatches, missing/extra/overlong/-/4-token rows, mask bits outside 0x70fffe, duration 0/5001/6000, start 3600000, out-of-order rows, +/leading-zero/oversized values, tabs/CRLF/BOM/unicode digits, 127/128/129-char lines, NUL and junk tails, whitespace-only tails, boundary rows 3599996 4 vs 3599996 5).

Before: 13 divergences, all header-valid/body-invalid timelines where Python over-reported the sequence. After: 0 divergences in 337 cases.

tools/tests/test_pad_input.py: valid multi-row body (with +-prefixed row and trailing whitespace) still advances the sequence; twelve rejected bodies contribute no sequence; an exhausted header with a rejected body no longer locks out commands. 39/39 pass; full relinker ctest 361/361; check_conventions and pr_overlap clean.

Host-only change to the Python tool; no title, GPU or console involved. No performance 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
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5033199662 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11885). Originally posted by [rooklz](https://github.com/rooklz) on 2026-10-27T11:33:25Z. --- ### What `previous_sequence` in `tools/pad_input.py` validated only the header of an `APS5_PAD_TIMELINE` command, while `Pad::InputCommandFile::read()` (`core/libs/prx/libScePad/include/InputCommandFile.hpp`) accepts or rejects the **whole** file: every event row (token count, `+`-prefixed unsigned values, button mask ⊆ `0x10fffe|0x200000|0x400000`, duration 1–5000, ordered non-overlapping events, `start ≤ 3600000 − duration`, line ≤ 127 chars) and the whitespace-only tail. A hand-edited command file with a valid header and an invalid body therefore reported a sequence the runtime never adopted: - the helpers normally skip past it, which is merely wasteful, but - with a header sequence of `18446744073709551615` and any rejected row, both `pad_input.py` and `pad_timeline.py` refuse every further command with "controller command sequence is exhausted" until the file is deleted — even though the runtime rejected that command and would adopt a fresh one. The single-pulse branch of `previous_sequence` already mirrored its consumer exactly; the timeline body mirror was missing. `previous_sequence` now validates the timeline body with the same acceptance rules as `read()`: each of the `count` rows must be three unsigned tokens ≤ 2⁶⁴−1 within the 127-char line budget, with the consumer's mask, duration, ordering and one-hour checks, and only whitespace may follow. A header whose body is rejected contributes no sequence, so the helpers resume from their own clock, and the exhaustion lockout above no longer triggers. ### 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. --> macOS 26.2, Apple M5 (arm64), CMake/Ninja, `ANYPS5_RELINKER_ONLY=ON`, `BUILD_TESTING=ON` (Python 3.13). Base: `8ff4baf534` (`upstream/main`), tested head: `fa895b282e`. Differential check on this Mac against the real consumer: `InputCommandFile.hpp` compiled with a driver printing `lastSequence` after the constructor's first read, compared with `pad_input.previous_sequence` over - 252 commands generated by `compile_timeline`/`pad_input.py` (event counts, repeats, gaps, every button combination incl. touch bits and stick forms) — all accepted by the consumer with the exact expected sequence, and - 85 adversarial files (count mismatches, missing/extra/overlong/`-`/4-token rows, mask bits outside `0x70fffe`, duration 0/5001/6000, start 3600000, out-of-order rows, `+`/leading-zero/oversized values, tabs/CRLF/BOM/unicode digits, 127/128/129-char lines, NUL and junk tails, whitespace-only tails, boundary rows `3599996 4` vs `3599996 5`). Before: 13 divergences, all header-valid/body-invalid timelines where Python over-reported the sequence. After: **0 divergences in 337 cases**. `tools/tests/test_pad_input.py`: valid multi-row body (with `+`-prefixed row and trailing whitespace) still advances the sequence; twelve rejected bodies contribute no sequence; an exhausted header with a rejected body no longer locks out commands. 39/39 pass; full relinker ctest 361/361; `check_conventions` and `pr_overlap` clean. Host-only change to the Python tool; no title, GPU or console involved. No performance claim. ### 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: <!-- #PR, or none --> none - [x] Fixes: <!-- issue it closes as Fixes #N, or none --> none - [x] Unblocks: <!-- title ID and Game bring-up discussion, e.g. PPSA01325 #3232, or none --> none - [x] GPUs tested: <!-- for AGC, shader recompiler or VideoOut changes: vendor, model, driver and OS of each GPU the GPU tests ran on; otherwise n/a --> n/a - [x] AI-assisted: <!-- yes / no --> yes
MarcZX10 commented 2026-10-27 11:44:19 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-27T11:44:19Z.

Review: CHANGES_REQUESTED


Please restore the required pull request template in the description. The current conventions check fails with three explicit findings: missing ### What, ### Tested, and ### Checklist headings. CONTRIBUTING.md requires copying the template, retaining its lines, and filling the checklist fields (including Depends on, Unblocks, GPUs tested, and AI-assisted). The current Problem/Change/Evidence/Tests sections contain useful detail, but do not satisfy that required format.

I reviewed the Python validator against Pad::InputCommandFile::read() and ran python3 -m unittest tools.tests.test_pad_input on the PR files: 14 tests passed. The Linux/Windows relinker jobs and ASan pass; macOS relinker remains pending. Please update the template and rerun conventions before merge.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5666514477 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11885#pullrequestreview-5666514477). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-27T11:44:19Z. **Review:** CHANGES_REQUESTED --- Please restore the required pull request template in the description. The current `conventions` check fails with three explicit findings: missing `### What`, `### Tested`, and `### Checklist` headings. `CONTRIBUTING.md` requires copying the template, retaining its lines, and filling the checklist fields (including Depends on, Unblocks, GPUs tested, and AI-assisted). The current Problem/Change/Evidence/Tests sections contain useful detail, but do not satisfy that required format. I reviewed the Python validator against `Pad::InputCommandFile::read()` and ran `python3 -m unittest tools.tests.test_pad_input` on the PR files: 14 tests passed. The Linux/Windows relinker jobs and ASan pass; macOS relinker remains pending. Please update the template and rerun conventions before merge.
MarcZX10 commented 2026-10-27 12:23:03 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-27T12:23:03Z.

Review: APPROVED


The PR template is restored with the required What, Tested, and Checklist sections, and the conventions check now passes. The implementation still matches the timeline validator change reviewed earlier; the local Python suite passed 14/14 cases. Hosted Windows/Linux relinker and ASan checks pass; macOS relinker jobs remain pending, but this Python-only change does not alter relinker code. I found no remaining blocker in this PR.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5666957448 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11885#pullrequestreview-5666957448). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-27T12:23:03Z. **Review:** APPROVED --- The PR template is restored with the required `What`, `Tested`, and `Checklist` sections, and the conventions check now passes. The implementation still matches the timeline validator change reviewed earlier; the local Python suite passed 14/14 cases. Hosted Windows/Linux relinker and ASan checks pass; macOS relinker jobs remain pending, but this Python-only change does not alter relinker code. I found no remaining blocker in this PR.
THEMANnt commented 2026-10-28 04:23:03 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by THEMANnt on 2026-10-28T04:23:03Z.

Review: APPROVED


Reviewed fa895b282e15f348bd13ef11bfee9222b5bb51f3 — approve. Resuming a command sequence now validates the entire timeline body rather than trusting a valid-looking header.

Windows/Python 3.11: head 19 passed, 2 skipped (21 total); author base 16 passed, 2 skipped (18 total). The old-production control fails the new malformed-body cases, including ordering, bounds, masks, count and trailing data. File read errors continue to propagate rather than being mistaken for an absent command. No real controller was exercised.

The inspected hosted Windows relinker job merged this exact head and completed successfully. This is not a full product or game build.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5677763800 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11885#pullrequestreview-5677763800). Originally posted by [THEMANnt](https://github.com/THEMANnt) on 2026-10-28T04:23:03Z. **Review:** APPROVED --- Reviewed `fa895b282e15f348bd13ef11bfee9222b5bb51f3` — approve. Resuming a command sequence now validates the entire timeline body rather than trusting a valid-looking header. Windows/Python 3.11: head 19 passed, 2 skipped (21 total); author base 16 passed, 2 skipped (18 total). The old-production control fails the new malformed-body cases, including ordering, bounds, masks, count and trailing data. File read errors continue to propagate rather than being mistaken for an absent command. No real controller was exercised. The inspected hosted Windows relinker job merged this exact head and completed successfully. This is not a full product or game build.

Pull request closed

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!11885
No description provided.