media: apply the local-file rule to the source reader, sink writer and MFCreateFile #663

Open
github-bot wants to merge 1 commit from github-bot/gh-663 into main AGit
Owner

@⁠coderanonymus on GitHub · 2026-11-24 06:24 UTC · original
coderanonymus:media-foundation-url-guard → main · +169 −15 · 1 files · 1 commits · open

What

media.rs proxies only mfplat!MFCreateSourceResolver. HostPolicy passes the rest of mfplat.dll and mfreadwrite.dll through. Four exports that take a URL or a path therefore bind straight to the host:

  • mfreadwrite!MFCreateSourceReaderFromURL
  • mfreadwrite!MFCreateSinkWriterFromURL
  • mfplat!MFCreateFile
  • mfplat!MFBeginCreateFile

The host's source reader calls IMFSourceResolver::CreateObjectFromURL internally. It gets that resolver from the real mfplat, not from our proxy. The host's MFCreateFile opens the path with the host's CreateFileW, not with files. So checked() and files::translate never run:

  • MFCreateSourceReaderFromURL(L"https://cdn.example.com/a.mp4", ...) fetches over the network, past modules::net.
  • MFCreateFile(..., L"\\\\server\\share\\a.mp4", ...) opens a share.
  • MFCreateFile(..., L"G:\\movies\\intro.mp4", ...) fails, because the host cannot see our virtual drives.

This change adds mfreadwrite.dll to the media module and registers the four exports. Each one runs the resolver's existing checked() first. On a refusal it returns the same 0xC00D36C3 and clears the out pointer, as create_from_url already did. Otherwise it calls the host's export with the checked path, which files::translate has rewritten. The sink writer checks its URL only when it gets no byte stream. With a byte stream, the URL only names the container type, the same as create_from_stream. The out-pointer clearing moves into a small checked_out helper, and create_from_url uses it too.

GetProcAddress lookups by name are covered too: kernel::host_override maps any name the registry knows.

Verification

  • Regression test every_media_foundation_url_entry_point_is_ours: asserts registry::lookup finds all four exports. On main none is registered, so it fails there.
  • New test url_entry_points_refuse_what_is_not_a_local_file: calls each wrapper with an https URL or a share path and a stale out pointer. It expects 0xC00D36C3 and a null out pointer, and it never reaches the host.
  • cargo clippy -p victory-hle --tests --target x86_64-pc-windows-msvc: clean. The only warning is the existing one in xmem.rs.
  • Same with --features victory-gpu/diagnostics: clean, with the same existing warning.
  • rustfmt --edition 2024 --check crates/victory-hle/src/modules/media.rs: clean.

Not run: victory-hle builds only for Windows. Both tests type-check but were not executed (Linux machine, no Wine). Nothing was run against a real Media Foundation host or a game.

No game data used.

🤖 Generated with Claude Code

**@⁠coderanonymus** on GitHub · 2026-11-24 06:24 UTC · [original](https://github.com/Marvisak/VIctory/pull/663) `coderanonymus:media-foundation-url-guard` → `main` · +169 −15 · 1 files · 1 commits · open ## What `media.rs` proxies only `mfplat!MFCreateSourceResolver`. `HostPolicy` passes the rest of `mfplat.dll` and `mfreadwrite.dll` through. Four exports that take a URL or a path therefore bind straight to the host: - `mfreadwrite!MFCreateSourceReaderFromURL` - `mfreadwrite!MFCreateSinkWriterFromURL` - `mfplat!MFCreateFile` - `mfplat!MFBeginCreateFile` The host's source reader calls `IMFSourceResolver::CreateObjectFromURL` internally. It gets that resolver from the real mfplat, not from our proxy. The host's `MFCreateFile` opens the path with the host's `CreateFileW`, not with `files`. So `checked()` and `files::translate` never run: - `MFCreateSourceReaderFromURL(L"https://cdn.example.com/a.mp4", ...)` fetches over the network, past `modules::net`. - `MFCreateFile(..., L"\\\\server\\share\\a.mp4", ...)` opens a share. - `MFCreateFile(..., L"G:\\movies\\intro.mp4", ...)` fails, because the host cannot see our virtual drives. This change adds `mfreadwrite.dll` to the media module and registers the four exports. Each one runs the resolver's existing `checked()` first. On a refusal it returns the same `0xC00D36C3` and clears the out pointer, as `create_from_url` already did. Otherwise it calls the host's export with the checked path, which `files::translate` has rewritten. The sink writer checks its URL only when it gets no byte stream. With a byte stream, the URL only names the container type, the same as `create_from_stream`. The out-pointer clearing moves into a small `checked_out` helper, and `create_from_url` uses it too. `GetProcAddress` lookups by name are covered too: `kernel::host_override` maps any name the registry knows. ## Verification - Regression test `every_media_foundation_url_entry_point_is_ours`: asserts `registry::lookup` finds all four exports. On main none is registered, so it fails there. - New test `url_entry_points_refuse_what_is_not_a_local_file`: calls each wrapper with an https URL or a share path and a stale out pointer. It expects `0xC00D36C3` and a null out pointer, and it never reaches the host. - `cargo clippy -p victory-hle --tests --target x86_64-pc-windows-msvc`: clean. The only warning is the existing one in `xmem.rs`. - Same with `--features victory-gpu/diagnostics`: clean, with the same existing warning. - `rustfmt --edition 2024 --check crates/victory-hle/src/modules/media.rs`: clean. Not run: `victory-hle` builds only for Windows. Both tests type-check but were not executed (Linux machine, no Wine). Nothing was run against a real Media Foundation host or a game. No game data used. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Only MFCreateSourceResolver was proxied. MFCreateSourceReaderFromURL,
MFCreateSinkWriterFromURL, MFCreateFile and MFBeginCreateFile bound
straight to the host, which resolves the URL with its own resolver and
opens the path with its own file calls. So an https or rtsp URL went to
the network past modules::net, a share path was opened, and a path on a
virtual drive failed because the host cannot see it.

They now run the resolver's local-file check first: a refusal returns
the same error and clears the out pointer, and an allowed path is
rewritten to its host folder before the host's export gets it. The sink
writer checks its URL only without a byte stream; with one, the URL only
names the container type.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:11:58 +00:00
Author
Owner

@⁠geiyiliyabumo on GitHub · 2026-11-24 12:41 UTC · original

Review: media local-file rule extended to the source reader / sink writer / file exports

Diff read: crates/victory-hle/src/modules/media.rs only, +169 / -15. Reviewed the full hunks, not the summary.

What it does

  • Adds four new host passthroughs, each gated by the existing checked/local rule: MFCreateSourceReaderFromURL, MFCreateSinkWriterFromURL, MFCreateFile, MFBeginCreateFile (media.rs:467-567), and registers mfreadwrite.dll alongside mfplat.dll in module() (media.rs:569-581).
  • Introduces checked_out (media.rs:152-160) that nulls the title's out pointer on a refusal, and refactors create_from_url to use it (behaviour unchanged).
  • MFCreateSinkWriterFromURL only checks the URL when stream.is_null() (media.rs:494-501); with a byte stream the URL is passed through raw as a container hint, matching create_from_stream and MS semantics (the host does not open it).
  • Two new tests: registry coverage of the four entry points, and that a refusal returns UNSUPPORTED_SCHEME before the host is called and leaves a null out pointer.

Findings
No correctness or memory-safety bugs found.

  • The url.as_ptr() / path.as_ptr() are used only within the lifetime of their owning Vec, so the transmuted host call never sees a dangling pointer.
  • Argument orders match the documented signatures for all four exports.
  • Minor nit (pre-existing pattern, not introduced here): when host::function(...) returns None the export returns UNSUPPORTED_SCHEME without clearing the out param (e.g. media.rs:476-478), unlike the refusal path. A title that pre-seeds the out pointer to non-null could observe it unchanged. Low risk, and MFCreateSourceResolver has the same shape.
  • Minor nit: begin_from_url still uses checked rather than checked_out (media.rs:335), so its cookie out param isn't cleared on refusal ? a now-more-visible inconsistency, out of this PR's scope.

Commands actually run (proxy cleared, --locked, CARGO_TARGET_DIR shared):

  • cargo xtask policy ? asset policy: 154 files ok (exit 0)
  • cargo clippy -p victory-hle --all-targets --locked -- -D warnings ? exit 0, no lint diagnostics. (Early runs showed per-crate "generated 1 warning" summaries; those were cargo's incremental lock-file-deletion noise on the shared target dir ? re-ran with CARGO_INCREMENTAL=0 and it is completely clean, 0 warnings.)
  • cargo clippy -p victory-hle --all-targets --features diagnostics --locked -- -D warnings ? exit 0, clean.
  • cargo test -p victory-hle --locked -- media ? 4 passed; 0 failed (only_local_files_reach_the_host, every_media_foundation_url_entry_point_is_ours, url_entry_points_refuse_what_is_not_a_local_file, interface_ids_are_the_resolvers).

Verdict: approve-worthy. Only the two minor nits above; neither blocks.

AI-assisted; synthetic tests only, no game files.

**@⁠geiyiliyabumo** on GitHub · 2026-11-24 12:41 UTC · [original](https://github.com/Marvisak/VIctory/pull/663#issuecomment-7131787990) ## Review: media local-file rule extended to the source reader / sink writer / file exports **Diff read:** `crates/victory-hle/src/modules/media.rs` only, +169 / -15. Reviewed the full hunks, not the summary. **What it does** - Adds four new host passthroughs, each gated by the existing `checked`/`local` rule: `MFCreateSourceReaderFromURL`, `MFCreateSinkWriterFromURL`, `MFCreateFile`, `MFBeginCreateFile` (`media.rs:467-567`), and registers `mfreadwrite.dll` alongside `mfplat.dll` in `module()` (`media.rs:569-581`). - Introduces `checked_out` (`media.rs:152-160`) that nulls the title's out pointer on a refusal, and refactors `create_from_url` to use it (behaviour unchanged). - `MFCreateSinkWriterFromURL` only checks the URL when `stream.is_null()` (`media.rs:494-501`); with a byte stream the URL is passed through raw as a container hint, matching `create_from_stream` and MS semantics (the host does not open it). - Two new tests: registry coverage of the four entry points, and that a refusal returns `UNSUPPORTED_SCHEME` before the host is called and leaves a null out pointer. **Findings** No correctness or memory-safety bugs found. - The `url.as_ptr()` / `path.as_ptr()` are used only within the lifetime of their owning `Vec`, so the transmuted host call never sees a dangling pointer. - Argument orders match the documented signatures for all four exports. - Minor nit (pre-existing pattern, not introduced here): when `host::function(...)` returns `None` the export returns `UNSUPPORTED_SCHEME` without clearing the out param (e.g. `media.rs:476-478`), unlike the refusal path. A title that pre-seeds the out pointer to non-null could observe it unchanged. Low risk, and `MFCreateSourceResolver` has the same shape. - Minor nit: `begin_from_url` still uses `checked` rather than `checked_out` (`media.rs:335`), so its cookie out param isn't cleared on refusal ? a now-more-visible inconsistency, out of this PR's scope. **Commands actually run** (proxy cleared, `--locked`, CARGO_TARGET_DIR shared): - `cargo xtask policy` ? `asset policy: 154 files ok` (exit 0) - `cargo clippy -p victory-hle --all-targets --locked -- -D warnings` ? exit 0, no lint diagnostics. (Early runs showed per-crate "generated 1 warning" summaries; those were cargo's incremental lock-file-deletion noise on the shared target dir ? re-ran with `CARGO_INCREMENTAL=0` and it is completely clean, 0 warnings.) - `cargo clippy -p victory-hle --all-targets --features diagnostics --locked -- -D warnings` ? exit 0, clean. - `cargo test -p victory-hle --locked -- media` ? `4 passed; 0 failed` (`only_local_files_reach_the_host`, `every_media_foundation_url_entry_point_is_ours`, `url_entry_points_refuse_what_is_not_a_local_file`, `interface_ids_are_the_resolvers`). **Verdict:** approve-worthy. Only the two minor nits above; neither blocks. *AI-assisted; synthetic tests only, no game files.*
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 00:33 UTC · original

Automated triage for the maintainers.

Needs rebase. This PR does not merge cleanly into current main (ac2525d). Conflicting files: crates/victory-hle/src/modules/media.rs.

The content has not been reviewed yet; it will be once the branch is rebased onto main.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 00:33 UTC · [original](https://github.com/Marvisak/VIctory/pull/663#issuecomment-7148630991) <!-- victory-triage v1 head=d4dcd0b63ad1d17d057ef8cd76583e581565146c verdict=needs-rebase at=2026-11-25T00:13:20Z --> Automated triage for the maintainers. **Needs rebase.** This PR does not merge cleanly into current `main` (ac2525d). Conflicting files: `crates/victory-hle/src/modules/media.rs`. The content has not been reviewed yet; it will be once the branch is rebased onto `main`. --- _Generated by [Claude Code](https://claude.ai/code)_
This pull request has changes conflicting with the target branch.
  • crates/victory-hle/src/modules/media.rs
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/663/head:github-bot/gh-663'
git switch 'github-bot/gh-663'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-663'
git switch 'github-bot/gh-663'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-663'
git switch 'github-bot/gh-663'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-663'
git switch 'main'
git merge --squash 'github-bot/gh-663'
git switch 'main'
git merge --ff-only 'github-bot/gh-663'
git switch 'main'
git merge 'github-bot/gh-663'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No reviewers
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.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!663
No description provided.