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

Open
coderanonymus wants to merge 1 commit from upstream-pr/663 into main
coderanonymus commented 2026-11-24 06:24:39 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by coderanonymus on 2026-11-24T06:24:39Z.


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

<!-- greyfinch-sync:Marvisak/VIctory:issue:6575996729 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/663). Originally posted by [coderanonymus](https://github.com/coderanonymus) on 2026-11-24T06:24:39Z. --- ## 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)
LAKSHYA-cmd-tech commented 2026-11-24 06:54:18 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by LAKSHYA-cmd-tech on 2026-11-24T06:28:48Z.

Review: APPROVED


LGTM! Tested on Windows 11 with MSVC Rust 1.98.1. All 88 tests in ictory-hle passed cleanly, including every_media_foundation_url_entry_point_is_ours and url_entry_points_refuse_what_is_not_a_local_file. The local-file rule and virtual path mapping now correctly intercept and protect all Media Foundation file/URL entry points.

<!-- greyfinch-sync:Marvisak/VIctory:review:6034672705 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/663#pullrequestreview-6034672705). Originally posted by [LAKSHYA-cmd-tech](https://github.com/LAKSHYA-cmd-tech) on 2026-11-24T06:28:48Z. **Review:** APPROVED --- LGTM! Tested on Windows 11 with MSVC Rust 1.98.1. All 88 tests in ictory-hle passed cleanly, including every_media_foundation_url_entry_point_is_ours and url_entry_points_refuse_what_is_not_a_local_file. The local-file rule and virtual path mapping now correctly intercept and protect all Media Foundation file/URL entry points.
mercuryVM commented 2026-11-24 11:03:51 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by mercuryVM on 2026-11-24T10:44:47Z.

Review: APPROVED


Tested d4dcd0b on Windows 11, RTX 5070, MSVC: cargo test -p victory-hle 89 passed, including every_media_foundation_url_entry_point_is_ours and url_entry_points_refuse_what_is_not_a_local_file. Clippy's 1 warning is the existing field_reassign_with_default at xmem.rs:747.

  • The gap is real: the host's MFCreateSourceReaderFromURL resolves through the real mfplat resolver, which never reaches our proxy. Checking the URL at each of the four entry points closes it.
  • MFCreateSinkWriterFromURL only checks the URL when there is no byte stream. With a stream, the URL just names the container type, so passing it through unchanged is correct and matches create_from_stream.
  • checked_out clears the out pointer on refusal at every entry point, including MFBeginCreateFile's cookie, so a title never sees stale memory there.

AI-assisted (Claude Code).

<!-- greyfinch-sync:Marvisak/VIctory:review:6037788917 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/663#pullrequestreview-6037788917). Originally posted by [mercuryVM](https://github.com/mercuryVM) on 2026-11-24T10:44:47Z. **Review:** APPROVED --- Tested d4dcd0b on Windows 11, RTX 5070, MSVC: `cargo test -p victory-hle` 89 passed, including `every_media_foundation_url_entry_point_is_ours` and `url_entry_points_refuse_what_is_not_a_local_file`. Clippy's 1 warning is the existing `field_reassign_with_default` at xmem.rs:747. - The gap is real: the host's `MFCreateSourceReaderFromURL` resolves through the real mfplat resolver, which never reaches our proxy. Checking the URL at each of the four entry points closes it. - `MFCreateSinkWriterFromURL` only checks the URL when there is no byte stream. With a stream, the URL just names the container type, so passing it through unchanged is correct and matches `create_from_stream`. - `checked_out` clears the out pointer on refusal at every entry point, including `MFBeginCreateFile`'s cookie, so a title never sees stale memory there. AI-assisted (Claude Code).
geiyiliyabumo commented 2026-11-24 13:02:10 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by geiyiliyabumo on 2026-11-24T12:41:31Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7131787990 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/663#issuecomment-7131787990). Originally posted by [geiyiliyabumo](https://github.com/geiyiliyabumo) on 2026-11-24T12:41:31Z. --- ## 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.*
Marvisak commented 2026-11-25 01:08:02 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T00:33:21Z.


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

<!-- greyfinch-sync:Marvisak/VIctory:comment:7148630991 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/663#issuecomment-7148630991). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T00:33:21Z. --- <!-- 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 cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/663:upstream-pr/663'
git switch 'upstream-pr/663'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/663'
git switch 'upstream-pr/663'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/663'
git switch 'upstream-pr/663'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/663'
git switch 'main'
git merge --squash 'upstream-pr/663'
git switch 'main'
git merge --ff-only 'upstream-pr/663'
git switch 'main'
git merge 'upstream-pr/663'
git push origin 'main'
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
Marvisak/VIctory!663
No description provided.