fix(libSceVideodec2): safely copy guest decode and flush buffers #20614

Merged
PrivacyOnion merged 4 commits from upstream-pr/20614 into main 2026-11-25 19:49:35 +00:00
PrivacyOnion commented 2026-11-15 11:08:36 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-15T11:08:36Z.


What

Copy guest InputData, FrameBuffer, OutputInfo, access unit bytes (auData), and decoded NV12 frame output (frameBuffer) through GuestCopyIn_nid_no_patch / GuestCopyOut_nid_no_patch (while preserving errno) in sceVideodec2Decode_nid_postfix, sceVideodec2Flush_nid_postfix, ClearOutput, EmitDecoded, and WriteNv12 in core/libs/prx/libSceVideodec2/Export.cpp, throwing "Videodec2: invalid argument pointer" on copy failure.

Tested

  • python tools/guest_pointer_audit.py libSceVideodec2 -> 0 direct guest pointer accesses in 0 exported functions
  • python tools/check_conventions.py --base upstream/main --head fix/videodec2-guest-copy -> All conventions checks passed. (exit code 0)
  • g++ -std=gnu++20 -fsyntax-only could not complete because 3rdparty/ffmpeg-core submodule headers (libavcodec/avcodec.h) are not checked out in this worktree.

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: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5322082901 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/20614). Originally posted by [PrivacyOnion](https://github.com/PrivacyOnion) on 2026-11-15T11:08:36Z. --- ### What Copy guest `InputData`, `FrameBuffer`, `OutputInfo`, access unit bytes (`auData`), and decoded NV12 frame output (`frameBuffer`) through `GuestCopyIn_nid_no_patch` / `GuestCopyOut_nid_no_patch` (while preserving `errno`) in `sceVideodec2Decode_nid_postfix`, `sceVideodec2Flush_nid_postfix`, `ClearOutput`, `EmitDecoded`, and `WriteNv12` in `core/libs/prx/libSceVideodec2/Export.cpp`, throwing `"Videodec2: invalid argument pointer"` on copy failure. ### Tested - `python tools/guest_pointer_audit.py libSceVideodec2` -> `0 direct guest pointer accesses in 0 exported functions` - `python tools/check_conventions.py --base upstream/main --head fix/videodec2-guest-copy` -> `All conventions checks passed.` (exit code 0) - `g++ -std=gnu++20 -fsyntax-only` could not complete because `3rdparty/ffmpeg-core` submodule headers (`libavcodec/avcodec.h`) are not checked out in this worktree. ### 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: n/a - [x] AI-assisted: yes
MarcZX10 commented 2026-11-15 11:39:05 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-15T11:39:05Z.

Review: COMMENTED


Reviewed — no blocking findings

The changed file was reviewed at head e99ed54bf51512e9cf496e2c456edcb3e9d02f94; I found no verified blocking defect, and the reported syntax check could not complete because FFmpeg headers were unavailable.

What I ran

Read the prepared description, commits, manifest, diff, and the full changed file through the pinned reader. No commands or tests were run.

Results

Check Result Note
Code review passed Changed file read in full
Tests and build not run Syntax check failure was author reported
Prepared review inputs passed No excluded changed files

Findings

Blocking

None.

Non-blocking

None.

Sources

Not verified

Tests and build were not run. The reported guest pointer audit and conventions check were author reported, not performed in this review. No changed files were excluded; core/libs/prx/libSceVideodec2/Export.cpp was read in full.

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5910472115 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/20614#pullrequestreview-5910472115). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-15T11:39:05Z. **Review:** COMMENTED --- # Reviewed — no blocking findings The changed file was reviewed at head `e99ed54bf51512e9cf496e2c456edcb3e9d02f94`; I found no verified blocking defect, and the reported syntax check could not complete because FFmpeg headers were unavailable. ## What I ran Read the prepared description, commits, manifest, diff, and the full changed file through the pinned reader. No commands or tests were run. ## Results | Check | Result | Note | |---|---|---| | Code review | passed | Changed file read in full | | Tests and build | not run | Syntax check failure was author reported | | Prepared review inputs | passed | No excluded changed files | ## Findings ### Blocking None. ### Non-blocking None. ## Sources - [Changed implementation at reviewed head](https://github.com/boykopovar/AnyPS5/blob/e99ed54bf51512e9cf496e2c456edcb3e9d02f94/core/libs/prx/libSceVideodec2/Export.cpp) ## Not verified Tests and build were not run. The reported guest pointer audit and conventions check were author reported, not performed in this review. No changed files were excluded; `core/libs/prx/libSceVideodec2/Export.cpp` was read in full. ## To get this to a good state Nothing is required.
MarcZX10 commented 2026-11-15 16:53:18 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-15T16:53:18Z.

Review: CHANGES_REQUESTED


Reviewed — changes requested

Changes are required before merge: reject undersized OutputInfo records before attempting the bounded copy.

What I ran

  • Reviewed head 55bef73ce83e070cd6a1708060b00e7963f15885 using the pinned repo_read.py reader.
  • No commands or tests were run.

Results

Check Result Note
Diff and source review passed One changed source file reviewed
Tests not run Author-reported checks were not rerun

Findings

Blocking

  • core/libs/prx/libSceVideodec2/Export.cpp:78: ReadSizedGuest accepts any thisSize, including values smaller than the 8-byte size field. WriteSizedGuest then treats that value as a successful copy length; a zero size causes no OutputInfo fields to be written, while short sizes can leave ClearOutput’s required invalid/empty result partly or entirely untouched. Reject sizes that cannot hold the required fields before using them, and return a structure-size error or equivalent failure.

Non-blocking

  • core/libs/prx/libSceVideodec2/Export.cpp:450: decoded output now allocates a staging vector for every frame before copying it to guest memory. Consider reusing per-decoder staging storage if this allocation is measurable on common decode workloads.

Not verified

  • No tests or builds were run. The PR description reports a guest pointer audit and convention check passing, and notes that syntax checking could not complete because FFmpeg headers were unavailable; these results were not independently verified.
  • core/libs/prx/libSceVideodec2/Export.cpp and core/libs/prx/libSceVideodec2/include/Api.hpp were read. The manifest lists one changed file and marks it included; files.json was not available through the reader, so excluded-file details were not verified.

To get this to a good state

  • Validate OutputInfo::thisSize against the minimum supported size before reading or writing the structure, then rerun relevant tests and checks on the updated head.
<!-- greyfinch-sync:boykopovar/AnyPS5:review:5911806948 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/20614#pullrequestreview-5911806948). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-15T16:53:18Z. **Review:** CHANGES_REQUESTED --- # Reviewed — changes requested Changes are required before merge: reject undersized `OutputInfo` records before attempting the bounded copy. ## What I ran - Reviewed head `55bef73ce83e070cd6a1708060b00e7963f15885` using the pinned `repo_read.py` reader. - No commands or tests were run. ## Results | Check | Result | Note | |---|---|---| | Diff and source review | passed | One changed source file reviewed | | Tests | not run | Author-reported checks were not rerun | ## Findings ### Blocking - `core/libs/prx/libSceVideodec2/Export.cpp:78`: `ReadSizedGuest` accepts any `thisSize`, including values smaller than the 8-byte size field. `WriteSizedGuest` then treats that value as a successful copy length; a zero size causes no `OutputInfo` fields to be written, while short sizes can leave `ClearOutput`’s required invalid/empty result partly or entirely untouched. Reject sizes that cannot hold the required fields before using them, and return a structure-size error or equivalent failure. ### Non-blocking - `core/libs/prx/libSceVideodec2/Export.cpp:450`: decoded output now allocates a staging vector for every frame before copying it to guest memory. Consider reusing per-decoder staging storage if this allocation is measurable on common decode workloads. ## Not verified - No tests or builds were run. The PR description reports a guest pointer audit and convention check passing, and notes that syntax checking could not complete because FFmpeg headers were unavailable; these results were not independently verified. - `core/libs/prx/libSceVideodec2/Export.cpp` and `core/libs/prx/libSceVideodec2/include/Api.hpp` were read. The manifest lists one changed file and marks it included; `files.json` was not available through the reader, so excluded-file details were not verified. ## To get this to a good state - Validate `OutputInfo::thisSize` against the minimum supported size before reading or writing the structure, then rerun relevant tests and checks on the updated head.
MarcZX10 commented 2026-11-16 06:57:36 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-16T06:57:36Z.

Review: APPROVED


Reviewed — looks good

The reviewed change at 29d0ff969445014d5f1e53350b44636e06e6b970 safely stages guest decode and flush buffers based on the inspected paths; no blocking defects were verified. Nothing blocks this; the points below are optional.

What I ran

No commands were run. I read the prepared diff and the changed source and test files at the pinned head.

Results

Check Result Note
Source review passed Changed implementation inspected
Tests not run No tests run during review

Findings

Blocking

None.

Non-blocking

None.

Not verified

No commands or tests were run. The PR description reports convention checks passed and syntax checking could not complete due to unavailable FFmpeg submodule headers; these were not independently run. Read: review/description.md, review/commits.md, review/manifest.json, review/diff.patch, core/libs/prx/libSceVideodec2/Export.cpp, core/libs/prx/libSceVideodec2/include/Api.hpp, and core/libs/tests/GuestVideodec2.cpp. The manifest lists both changed files as included, and both were read. No excluded changed files were listed.

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5916107651 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/20614#pullrequestreview-5916107651). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-16T06:57:36Z. **Review:** APPROVED --- # Reviewed — looks good The reviewed change at `29d0ff969445014d5f1e53350b44636e06e6b970` safely stages guest decode and flush buffers based on the inspected paths; no blocking defects were verified. Nothing blocks this; the points below are optional. ## What I ran No commands were run. I read the prepared diff and the changed source and test files at the pinned head. ## Results | Check | Result | Note | |---|---|---| | Source review | passed | Changed implementation inspected | | Tests | not run | No tests run during review | ## Findings ### Blocking None. ### Non-blocking None. ## Not verified No commands or tests were run. The PR description reports convention checks passed and syntax checking could not complete due to unavailable FFmpeg submodule headers; these were not independently run. Read: `review/description.md`, `review/commits.md`, `review/manifest.json`, `review/diff.patch`, `core/libs/prx/libSceVideodec2/Export.cpp`, `core/libs/prx/libSceVideodec2/include/Api.hpp`, and `core/libs/tests/GuestVideodec2.cpp`. The manifest lists both changed files as included, and both were read. No excluded changed files were listed. ## To get this to a good state Nothing is required.
MarcZX10 commented 2026-11-16 07:16:39 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-16T07:16:39Z.

Review: APPROVED


Reviewed — looks good

The review covers head a1578a6638ca4c3ac7c1af90813c13e4e7903d47; the code changes and added tests reviewed show no verified blocking defect, while builds and runtime tests were not run.

What I ran

Read the prepared diff and changed source at the pinned head. No commands or tests were run.

Results

Check Result Note
Diff and changed code review passed Three changed files reviewed
Tests and build not run No execution environment provided

Negative control

Not run; no test execution was available.

Findings

Blocking

None.

Non-blocking

None.

Sources

The review used the prepared diff, manifest and description, plus head contents of core/libs/prx/libSceVideodec2/Export.cpp, core/libs/tests/GuestVideodec2.cpp, and docs/dev/debt/changes/fix-videodec2-decode-guest-copy.md.

Not verified

No tests or build were run. The description reports prior audit/convention checks and a compile attempt blocked by missing FFmpeg submodule headers; these were not independently verified. No files were excluded: all three files listed as reviewed in the manifest were read.

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5916282254 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/20614#pullrequestreview-5916282254). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-16T07:16:39Z. **Review:** APPROVED --- # Reviewed — looks good The review covers head `a1578a6638ca4c3ac7c1af90813c13e4e7903d47`; the code changes and added tests reviewed show no verified blocking defect, while builds and runtime tests were not run. ## What I ran Read the prepared diff and changed source at the pinned head. No commands or tests were run. ## Results | Check | Result | Note | |---|---|---| | Diff and changed code review | passed | Three changed files reviewed | | Tests and build | not run | No execution environment provided | ## Negative control Not run; no test execution was available. ## Findings ### Blocking None. ### Non-blocking None. ## Sources The review used the prepared diff, manifest and description, plus head contents of `core/libs/prx/libSceVideodec2/Export.cpp`, `core/libs/tests/GuestVideodec2.cpp`, and `docs/dev/debt/changes/fix-videodec2-decode-guest-copy.md`. ## Not verified No tests or build were run. The description reports prior audit/convention checks and a compile attempt blocked by missing FFmpeg submodule headers; these were not independently verified. No files were excluded: all three files listed as reviewed in the manifest were read. ## To get this to a good state Nothing is required.
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!20614
No description provided.