HLE: require two hex digits in percent escapes #480

Merged
enzoduarte1 merged 1 commit from upstream-pr/480 into main 2026-11-25 00:11:17 +00:00
enzoduarte1 commented 2026-11-24 03:53:22 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by enzoduarte1 on 2026-11-24T03:53:22Z.


What

media::percent_decode used u8::from_str_radix(.., 16) directly on the two bytes after %. That parser accepts a leading +, so a file: URL such as file:///C:/a%+1.mp4 decoded %+1 into byte 0x01 instead of leaving the escape literal.

The decoder now requires both characters to be ASCII hex digits before parsing. Real escapes (%20, %FF) still decode; malformed ones (%+1, %2, %%20) are copied verbatim. Tests cover those cases.

Tested

  • Windows 11, Rust 1.98.1, x86_64-pc-windows-gnu (no MSVC linker on this machine).
  • cargo test -p victory-hle --lib media::: 3 passed.
  • cargo test --workspace --exclude victory-loader -- --test-threads=1: all suites passed.
  • cargo clippy -p victory-hle --all-targets -- -A clippy::field_reassign_with_default -D warnings: clean. The allowed lint is the pre-existing warning fixed by PR #355.
  • rustfmt --edition 2024 --check crates/victory-hle/src/modules/media.rs and git diff --check: clean.
  • cargo xtask policy: 151 files ok. No game files or data taken from them were added.
  • Not tested: cargo test -p victory-loader --test load_probe. Its fixture passes MSVC's /DELAYLOAD flag, which MinGW rejects here; the same failure occurs on unmodified main.

Checklist

  • cargo fmt, cargo clippy --workspace --all-targets and cargo test --workspace pass — see the toolchain limitations above; the changed crate is clean.
  • cargo xtask policy passes. The change adds no game files or data taken from them (docs/asset-policy.md).
  • If an AI tool wrote part of this change, the description says so: an AI tool assisted with the code and test; I reviewed and ran them.
<!-- greyfinch-sync:Marvisak/VIctory:issue:6574224448 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/480). Originally posted by [enzoduarte1](https://github.com/enzoduarte1) on 2026-11-24T03:53:22Z. --- ## What `media::percent_decode` used `u8::from_str_radix(.., 16)` directly on the two bytes after `%`. That parser accepts a leading `+`, so a `file:` URL such as `file:///C:/a%+1.mp4` decoded `%+1` into byte `0x01` instead of leaving the escape literal. The decoder now requires both characters to be ASCII hex digits before parsing. Real escapes (`%20`, `%FF`) still decode; malformed ones (`%+1`, `%2`, `%%20`) are copied verbatim. Tests cover those cases. ## Tested - Windows 11, Rust 1.98.1, `x86_64-pc-windows-gnu` (no MSVC linker on this machine). - `cargo test -p victory-hle --lib media::`: 3 passed. - `cargo test --workspace --exclude victory-loader -- --test-threads=1`: all suites passed. - `cargo clippy -p victory-hle --all-targets -- -A clippy::field_reassign_with_default -D warnings`: clean. The allowed lint is the pre-existing warning fixed by PR #355. - `rustfmt --edition 2024 --check crates/victory-hle/src/modules/media.rs` and `git diff --check`: clean. - `cargo xtask policy`: 151 files ok. No game files or data taken from them were added. - Not tested: `cargo test -p victory-loader --test load_probe`. Its fixture passes MSVC's `/DELAYLOAD` flag, which MinGW rejects here; the same failure occurs on unmodified `main`. ## Checklist - [ ] `cargo fmt`, `cargo clippy --workspace --all-targets` and `cargo test --workspace` pass — see the toolchain limitations above; the changed crate is clean. - [x] `cargo xtask policy` passes. The change adds no game files or data taken from them (`docs/asset-policy.md`). - [x] If an AI tool wrote part of this change, the description says so: an AI tool assisted with the code and test; I reviewed and ran them.
mercuryVM commented 2026-11-24 06:53:18 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by mercuryVM on 2026-11-24T05:08:10Z.

Review: APPROVED


Tested 75fe6c0 on Windows 11, RTX 5070, MSVC: cargo test --workspace --no-fail-fast passes (265 passed, 0 failed), including load_probe.

  • Confirmed the bug: u8::from_str_radix accepts a leading +, so %+1 decoded to 0x01 before this change.
  • With the is_ascii_hexdigit filter the later from_utf8 can no longer fail, so it is now redundant but harmless.
  • Traced %%20: the first % sees %2, fails the filter and is copied, then %20 decodes, giving % as the test expects.

No issues found.

AI-assisted (Claude Code).

<!-- greyfinch-sync:Marvisak/VIctory:review:6034013794 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/480#pullrequestreview-6034013794). Originally posted by [mercuryVM](https://github.com/mercuryVM) on 2026-11-24T05:08:10Z. **Review:** APPROVED --- Tested 75fe6c0 on Windows 11, RTX 5070, MSVC: `cargo test --workspace --no-fail-fast` passes (265 passed, 0 failed), including `load_probe`. - Confirmed the bug: `u8::from_str_radix` accepts a leading `+`, so `%+1` decoded to 0x01 before this change. - With the `is_ascii_hexdigit` filter the later `from_utf8` can no longer fail, so it is now redundant but harmless. - Traced `%%20`: the first `%` sees `%2`, fails the filter and is copied, then `%20` decodes, giving `% ` as the test expects. No issues found. AI-assisted (Claude Code).
jeremygold02 commented 2026-11-24 18:05:52 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by jeremygold02 on 2026-11-24T17:35:48Z.


Verification at 75fe6c02b278f18eab33ad893bda1dd68d176287:

cargo test --locked -p victory-hle --lib percent_decode_requires_two_hex_digits -- --test-threads=1 passed (1 passed, 0 failed). The test covers valid %20, signed %+1, incomplete %2, overlapping %%20, and non-hex %2G escapes; malformed escapes remain literal while later valid escapes still decode.

This verification was AI-assisted.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7139428403 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/480#issuecomment-7139428403). Originally posted by [jeremygold02](https://github.com/jeremygold02) on 2026-11-24T17:35:48Z. --- Verification at `75fe6c02b278f18eab33ad893bda1dd68d176287`: `cargo test --locked -p victory-hle --lib percent_decode_requires_two_hex_digits -- --test-threads=1` passed (`1 passed, 0 failed`). The test covers valid `%20`, signed `%+1`, incomplete `%2`, overlapping `%%20`, and non-hex `%2G` escapes; malformed escapes remain literal while later valid escapes still decode. This verification was AI-assisted.
upstream-sync closed this pull request 2026-11-25 01:03:55 +00:00
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!480
No description provided.