fix(videodec2): validate ClearOutput destinations upfront before mutating output #21081

Merged
Kikoarl merged 1 commit from upstream-pr/21081 into main 2026-11-28 07:53:23 +00:00
Kikoarl commented 2026-11-15 20:20:25 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Kikoarl on 2026-11-15T20:20:25Z.


What

Validates cleared guest destinations upfront in ClearOutput (core/libs/prx/libSceVideodec2/Export.cpp), closing the remaining transactional gap after #20614 landed checked CopyInGuest/CopyOutGuest/auBytes:

  • Checks optional frame (sizeof(FrameBuffer)) before output (min(thisSize, sizeof(OutputInfo))) under GuestArena::HostWrite paired with GuestWritable_nid_no_patch while preserving caller errno.
  • Throws Videodec2: invalid argument pointer without mutating either struct and without opening output in HostWrite when frame is read-only (keeping write-watched output pages clean on Windows as well as Linux). Applies uniformly to both sceVideodec2Decode_nid_postfix and sceVideodec2Flush_nid_postfix.
  • Extends core/libs/tests/GuestVideodec2HevcAliases.cpp with unreadable/unwritable pointer, errno preservation, armed GuestArena (std::array<void*, 64> drain loop for 32 pages in kSpan = 0x20000), sceVideodec2Decode/sceVideodec2Flush read-only frame non-mutation/non-dirtying, and page-straddling unwritable output checks, plus debt in docs/dev/debt/changes/fix-libSceVideodec2-decode-copyin.md.

Tested

  • Linux x86_64 Release RAM-disk build (BUILD_TESTING=ON), rebased onto origin/main (115a7036e2, PR head 7b2b577729):
    • ctest --test-dir /tmp/anyps5_verify_build --output-on-failure -R "^(guest_videodec2|guest_videodec2_hevc_aliases|guest_hevc_metadata|guest_videodec2_unimplemented)$": 4/4 passed (0.24 s), including guest_videodec2_hevc_aliases (0.01 s).
  • python3 tools/debt_fold.py --check and python3 tools/check_conventions.py --base origin/main: passed cleanly.

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 and the licence notice of code adapted from upstream (see AGENTS.md)
  • 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: none
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5326792301 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/21081). Originally posted by [Kikoarl](https://github.com/Kikoarl) on 2026-11-15T20:20:25Z. --- ### What Validates cleared guest destinations upfront in `ClearOutput` (`core/libs/prx/libSceVideodec2/Export.cpp`), closing the remaining transactional gap after #20614 landed checked `CopyInGuest`/`CopyOutGuest`/`auBytes`: - Checks optional `frame` (`sizeof(FrameBuffer)`) before `output` (`min(thisSize, sizeof(OutputInfo))`) under `GuestArena::HostWrite` paired with `GuestWritable_nid_no_patch` while preserving caller `errno`. - Throws `Videodec2: invalid argument pointer` without mutating either struct and without opening `output` in `HostWrite` when `frame` is read-only (keeping write-watched output pages clean on Windows as well as Linux). Applies uniformly to both `sceVideodec2Decode_nid_postfix` and `sceVideodec2Flush_nid_postfix`. - Extends `core/libs/tests/GuestVideodec2HevcAliases.cpp` with unreadable/unwritable pointer, `errno` preservation, armed `GuestArena` (`std::array<void*, 64>` drain loop for 32 pages in `kSpan = 0x20000`), `sceVideodec2Decode`/`sceVideodec2Flush` read-only `frame` non-mutation/non-dirtying, and page-straddling unwritable `output` checks, plus debt in `docs/dev/debt/changes/fix-libSceVideodec2-decode-copyin.md`. ### Tested - Linux x86_64 Release RAM-disk build (`BUILD_TESTING=ON`), rebased onto `origin/main` (`115a7036e2`, PR head `7b2b577729`): - `ctest --test-dir /tmp/anyps5_verify_build --output-on-failure -R "^(guest_videodec2|guest_videodec2_hevc_aliases|guest_hevc_metadata|guest_videodec2_unimplemented)$"`: 4/4 passed (`0.24 s`), including `guest_videodec2_hevc_aliases` (`0.01 s`). - `python3 tools/debt_fold.py --check` and `python3 tools/check_conventions.py --base origin/main`: passed cleanly. ### Checklist - [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) and the licence notice of code adapted from upstream (see AGENTS.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 - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: none - [x] AI-assisted: yes
PrivacyOnion commented 2026-11-15 22:47:51 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-15T22:47:51Z.

Review: CHANGES_REQUESTED


Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against e1878384d6:

  • Conventions: tools/check_conventions.py failed; git diff --check clean.
    (pull request): error: [pr-template] Fill in the pull request template: fill Depends on with #N or none
    1 findings, 1 errors; GitHub shows at most 10 error annotations, the job summary lists all
    
  • Build: guest_videodec2_hevc_aliases_tests built cleanly.
  • CTest (guest_videodec2_hevc_aliases):
    1/1 Test #4872: guest_videodec2_hevc_aliases .....   Passed    0.02 sec
    100% tests passed, 0 tests failed out of 1
    

Requesting changes for the points above.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5913329482 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/21081#pullrequestreview-5913329482). Originally posted by [PrivacyOnion](https://github.com/PrivacyOnion) on 2026-11-15T22:47:51Z. **Review:** CHANGES_REQUESTED --- Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against `e1878384d6`: - **Conventions**: `tools/check_conventions.py` failed; `git diff --check` clean. ``` (pull request): error: [pr-template] Fill in the pull request template: fill Depends on with #N or none 1 findings, 1 errors; GitHub shows at most 10 error annotations, the job summary lists all ``` - **Build**: `guest_videodec2_hevc_aliases_tests` built cleanly. - **CTest** (`guest_videodec2_hevc_aliases`): ``` 1/1 Test #4872: guest_videodec2_hevc_aliases ..... Passed 0.02 sec 100% tests passed, 0 tests failed out of 1 ``` Requesting changes for the points above.
MarcZX10 commented 2026-11-23 01:48:06 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-23T01:48:06Z.

Review: APPROVED


Reviewed — looks good

Nothing blocks this change; the points below are optional.

What I ran

Reviewed head e1878384d6cb76c5fd3ac317be2018d213e3ac69 using repo_read.py to inspect the prepared diff, the changed files, and relevant helper and caller code. No build or tests were run; the commands in the description are author-reported.

Results

Check Result Note
Changed code review passed All three changed files and their added lines were read.
Build and tests not run Only author-reported results are available.

Findings

Blocking

None.

Non-blocking

None.

Not verified

  • Build, tests, and convention checks were not run in this review.
  • files.json was unavailable in the review folder, so excluded paths and any repository-wide review coverage beyond the manifest could not be confirmed.
  • Console behavior for an unmapped input pointer is unmeasured, as the change’s debt note states.

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6015721718 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/21081#pullrequestreview-6015721718). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-23T01:48:06Z. **Review:** APPROVED --- # Reviewed — looks good Nothing blocks this change; the points below are optional. ## What I ran Reviewed head `e1878384d6cb76c5fd3ac317be2018d213e3ac69` using `repo_read.py` to inspect the prepared diff, the changed files, and relevant helper and caller code. No build or tests were run; the commands in the description are author-reported. ## Results | Check | Result | Note | |---|---|---| | Changed code review | passed | All three changed files and their added lines were read. | | Build and tests | not run | Only author-reported results are available. | ## Findings ### Blocking None. ### Non-blocking None. ## Not verified - Build, tests, and convention checks were not run in this review. - `files.json` was unavailable in the review folder, so excluded paths and any repository-wide review coverage beyond the manifest could not be confirmed. - Console behavior for an unmapped input pointer is unmeasured, as the change’s debt note states. ## To get this to a good state Nothing is required.
MarcZX10 commented 2026-11-25 09:45:11 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-25T09:45:11Z.

Review: COMMENTED


Reviewed — no blocking findings

The reviewed change at 3afcb24d6ccfce02bf203c8a0e6bf4dfe2c81d6b has no verified blocking defect; checks reported by the author were not run in this review.

What I ran

Read the prepared description, commit summary, manifest, and diff, then inspected the changed code and relevant guest-memory helper definitions through repo_read.py. No commands or tests were run.

Results

Check Result Note
Diff and changed code passed Three changed files inspected
Author-reported tests not run Reported as passing in the PR description
Negative controls not run Results are author-reported

Negative control

Not run during this review. The author reports two negative controls in the PR description; those results were not independently verified.

Findings

Blocking

None.

Non-blocking

None.

Sources

Not verified

No tests or negative controls were run here. Console behavior is not verified. The PR description and debt entry identify unchecked access-unit data reads and EmitDecoded writes as remaining work; those behaviors were not audited in depth. Read: core/libs/prx/libSceVideodec2/Export.cpp (relevant ranges), core/libs/tests/GuestVideodec2HevcAliases.cpp (full file), and docs/dev/debt/changes/fix-libSceVideodec2-decode-copyin.md (full file). No changed files were excluded by the manifest.

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6055204599 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/21081#pullrequestreview-6055204599). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-25T09:45:11Z. **Review:** COMMENTED --- # Reviewed — no blocking findings The reviewed change at `3afcb24d6ccfce02bf203c8a0e6bf4dfe2c81d6b` has no verified blocking defect; checks reported by the author were not run in this review. ## What I ran Read the prepared description, commit summary, manifest, and diff, then inspected the changed code and relevant guest-memory helper definitions through `repo_read.py`. No commands or tests were run. ## Results | Check | Result | Note | |---|---|---| | Diff and changed code | passed | Three changed files inspected | | Author-reported tests | not run | Reported as passing in the PR description | | Negative controls | not run | Results are author-reported | ## Negative control Not run during this review. The author reports two negative controls in the PR description; those results were not independently verified. ## Findings ### Blocking None. ### Non-blocking None. ## Sources - [Export.cpp at reviewed head](https://github.com/boykopovar/AnyPS5/blob/3afcb24d6ccfce02bf203c8a0e6bf4dfe2c81d6b/core/libs/prx/libSceVideodec2/Export.cpp) - [GuestVideodec2HevcAliases.cpp at reviewed head](https://github.com/boykopovar/AnyPS5/blob/3afcb24d6ccfce02bf203c8a0e6bf4dfe2c81d6b/core/libs/tests/GuestVideodec2HevcAliases.cpp) - [Change debt entry at reviewed head](https://github.com/boykopovar/AnyPS5/blob/3afcb24d6ccfce02bf203c8a0e6bf4dfe2c81d6b/docs/dev/debt/changes/fix-libSceVideodec2-decode-copyin.md) ## Not verified No tests or negative controls were run here. Console behavior is not verified. The PR description and debt entry identify unchecked access-unit data reads and `EmitDecoded` writes as remaining work; those behaviors were not audited in depth. Read: `core/libs/prx/libSceVideodec2/Export.cpp` (relevant ranges), `core/libs/tests/GuestVideodec2HevcAliases.cpp` (full file), and `docs/dev/debt/changes/fix-libSceVideodec2-decode-copyin.md` (full file). No changed files were excluded by the manifest. ## To get this to a good state Nothing is required.
MarcZX10 commented 2026-11-26 11:34:19 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-26T11:34:19Z.

Review: APPROVED


Reviewed — looks good

The change validates the caller’s frame and output destinations before clearing output state; the reviewed code has no verified blocking defects.

What I ran

  • Reviewed head 7b2b5777292016e57d0fd8063690452c706c5618.
  • Read the prepared description, commit summary, manifest and diff, plus all three changed files and targeted caller/helper definitions through repo_read.py.
  • No commands or tests were run. The checks listed in the PR description are author-reported.

Results

Check Result Note
Code review passed All changed files read
Automated checks not run PR description reports four tests and two checks passed
Console behavior not run No hardware measurement supplied

Findings

Blocking

None.

Non-blocking

None.

Not verified

  • Linux build and test results, debt fold check, and conventions check were not run by this review.
  • Console behavior for invalid pointers and EmitDecoded metadata writes remain unmeasured, as the change’s debt note states.
  • No files were excluded: the manifest lists all three changed files as included, and each was read.

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6073443661 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/21081#pullrequestreview-6073443661). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-26T11:34:19Z. **Review:** APPROVED --- # Reviewed — looks good The change validates the caller’s frame and output destinations before clearing output state; the reviewed code has no verified blocking defects. ## What I ran - Reviewed head `7b2b5777292016e57d0fd8063690452c706c5618`. - Read the prepared description, commit summary, manifest and diff, plus all three changed files and targeted caller/helper definitions through `repo_read.py`. - No commands or tests were run. The checks listed in the PR description are author-reported. ## Results | Check | Result | Note | |---|---|---| | Code review | passed | All changed files read | | Automated checks | not run | PR description reports four tests and two checks passed | | Console behavior | not run | No hardware measurement supplied | ## Findings ### Blocking None. ### Non-blocking None. ## Not verified - Linux build and test results, debt fold check, and conventions check were not run by this review. - Console behavior for invalid pointers and `EmitDecoded` metadata writes remain unmeasured, as the change’s debt note states. - No files were excluded: the manifest lists all three changed files as included, and each was read. ## To get this to a good state Nothing is required.
PrivacyOnion commented 2026-11-27 11:46:53 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-27T11:46:53Z.

Review: APPROVED


Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against 7b2b577729:

  • Conventions: tools/check_conventions.py passed.
  • Build: guest_videodec2_hevc_aliases_tests built cleanly.
  • CTest (guest_videodec2_hevc_aliases):
    1/1 Test #6162: guest_videodec2_hevc_aliases .....   Passed    0.04 sec
    100% tests passed, 0 tests failed out of 1
    
  • Negative control: with core/libs/prx/libSceVideodec2/Export.cpp reverted to main and the new tests kept, the suite fails:
    1/1 Test #6162: guest_videodec2_hevc_aliases .....***Failed    0.03 sec
    0% tests passed, 1 tests failed out of 1
    
    Restoring the change makes it pass again.
  • Code reading:
    • Verified Export.cpp ClearOutput checks optional frame (sizeof(FrameBuffer)) writability before output validation, throwing Videodec2: invalid argument pointer without opening output or mutating state when frame is unwritable
    • Verified OutputInfo destination pointer null check and localOutput.thisSize >= offsetof(OutputInfo, frameFormat) bounds check before output writability check
    • Verified HostWrite + GuestWritable_nid_no_patch pairing under saved and restored errno preservation in writableGuest helper
    • Verified test coverage in GuestVideodec2HevcAliases.cpp exercising unreadable input, unwritable/read-only frame, unwritable/straddling output, errno preservation, and dirty page write-watch tracking under GuestArena on Linux and Windows
    • Verified debt fragment docs/dev/debt/changes/fix-libSceVideodec2-decode-copyin.md adheres to AGENTS.md conventions and records unmeasured hardware behavior

Looks Good To Me

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6087650909 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/21081#pullrequestreview-6087650909). Originally posted by [PrivacyOnion](https://github.com/PrivacyOnion) on 2026-11-27T11:46:53Z. **Review:** APPROVED --- Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against `7b2b577729`: - **Conventions**: `tools/check_conventions.py` passed. - **Build**: `guest_videodec2_hevc_aliases_tests` built cleanly. - **CTest** (`guest_videodec2_hevc_aliases`): ``` 1/1 Test #6162: guest_videodec2_hevc_aliases ..... Passed 0.04 sec 100% tests passed, 0 tests failed out of 1 ``` - **Negative control**: with `core/libs/prx/libSceVideodec2/Export.cpp` reverted to `main` and the new tests kept, the suite fails: ``` 1/1 Test #6162: guest_videodec2_hevc_aliases .....***Failed 0.03 sec 0% tests passed, 1 tests failed out of 1 ``` Restoring the change makes it pass again. - **Code reading**: - Verified Export.cpp ClearOutput checks optional frame (sizeof(FrameBuffer)) writability before output validation, throwing Videodec2: invalid argument pointer without opening output or mutating state when frame is unwritable - Verified OutputInfo destination pointer null check and localOutput.thisSize >= offsetof(OutputInfo, frameFormat) bounds check before output writability check - Verified HostWrite + GuestWritable_nid_no_patch pairing under saved and restored errno preservation in writableGuest helper - Verified test coverage in GuestVideodec2HevcAliases.cpp exercising unreadable input, unwritable/read-only frame, unwritable/straddling output, errno preservation, and dirty page write-watch tracking under GuestArena on Linux and Windows - Verified debt fragment docs/dev/debt/changes/fix-libSceVideodec2-decode-copyin.md adheres to AGENTS.md conventions and records unmeasured hardware behavior Looks Good To Me
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!21081
No description provided.