fix(formats,core): Layout::copy_table panics on render_xor & misses 3D depth_pitch overlap check; empty env vars in default_dir #320

Closed
opened 2026-12-02 09:15:39 +00:00 by github-bot · 1 comment
Owner

@⁠RUIZ-Enrique-25002136 on GitHub · 2026-12-02 09:14 UTC · original

Summary

Three platform-independent bugs exist in crates/victory-formats/src/texture.rs and crates/victory-core/src/config.rs:

  1. Layout::copy_table panics with an out-of-bounds index when given a configure_render_xor layout (SW_64KB_R_X) instead of returning Err(Error::Unsupported).
  2. Layout::copy_table omits the depth > 1 && depth_pitch < slice_bytes overlap validation enforced by Layout::detile / Layout::tile.
  3. config::default_dir does not filter empty LOCALAPPDATA, XDG_CACHE_HOME, or HOME values, producing relative paths in the current working directory.

Evidence (file:line & Code Proof)

1. Out-of-Bounds Panic in Layout::copy_table on render_xor Layouts

  • crates/victory-formats/src/texture.rs:548-558, 576-599, 653-658, 958-996:
    For SW_64KB_R_X (d.swizzle.xor() == true), Layout::tiled leaves self.pattern = &EMPTY_PATTERN ([Vec::new(); 3]). Layout::configure_render_xor sets self.render_xor = Some(config), causing Layout::addressable() (texture.rs:597-599) to return true.
    Layout::offset (628) and Layout::walk (774) handle self.render_xor, whereas Layout::copy_table (958-996) skips checking self.render_xor and calls self.column(m, 0) (657), which indexes self.pattern[0][(x % bw) as usize] on an empty Vec and panics.
    crates/victory-gpu/src/detile.rs:758 calls layout.copy_table(...) expecting Err(_) to map to Why::NoTable and fall back to CPU detiling.

2. Missing 3D Depth-Slice Overlap Check in Layout::copy_table

  • crates/victory-formats/src/texture.rs:963-971 vs 751-764 (Layout::walk):
    Layout::walk rejects overlapping depth slices with if depth > 1 && depth_pitch < slice_bytes { return Err(Error::TooSmall); }.
    Layout::copy_table (whose doc promises "The same checks as the detile") omits this check, allowing depth > 1 with depth_pitch < slice_bytes (including depth_pitch == 0) to return overlapping CopyRow::linear offsets.

3. Empty Env Vars Produce Relative Paths in config::default_dir

  • crates/victory-core/src/config.rs:146-156 (default_dir):
    Every other env helper in config.rs (env_path:81, explicit_config_path:125, home_override:141) filters empty strings via .filter(|v| !v.is_empty()), whereas default_dir calls std::env::var_os("LOCALAPPDATA"), std::env::var_os("XDG_CACHE_HOME"), and std::env::var_os("HOME") without filtering empty values (violating the XDG Base Directory spec and creating relative victory/cache / .cache/victory/cache paths in CWD).

Impact

  • copy_table panics instead of falling back to CPU detiling when given a render_xor layout, and silently produces corrupt overlapping 3D CopyTables when depth_pitch < slice_bytes.
  • Empty LOCALAPPDATA/XDG_CACHE_HOME/HOME causes default_dir to resolve inside CWD (failing ensure_outside_repo when run from the repo or polluting CWD).

AI-Ready Fix Specification

  1. In crates/victory-formats/src/texture.rs (Layout::copy_table):
    • Return Err(Error::Unsupported) if !self.addressable() || self.render_xor.is_some().
    • Compute slice_bytes and enforce if depth > 1 && depth_pitch < slice_bytes { return Err(Error::TooSmall); }, matching Layout::walk.
  2. In crates/victory-core/src/config.rs (default_dir), filter empty env values with .filter(|v| !v.is_empty()) for LOCALAPPDATA, XDG_CACHE_HOME, and HOME.
  3. Add unit tests in victory-formats (for render_xor -> Err(Error::Unsupported) and overlapping 3D depth_pitch -> Err(Error::TooSmall)) and victory-core (for empty LOCALAPPDATA/XDG_CACHE_HOME/HOME), and verify with cargo test --locked -p victory-formats -p victory-core.
**@⁠RUIZ-Enrique-25002136** on GitHub · 2026-12-02 09:14 UTC · [original](https://github.com/Androtim/MiniVI/issues/320) ## Summary Three platform-independent bugs exist in `crates/victory-formats/src/texture.rs` and `crates/victory-core/src/config.rs`: 1. `Layout::copy_table` panics with an out-of-bounds index when given a `configure_render_xor` layout (`SW_64KB_R_X`) instead of returning `Err(Error::Unsupported)`. 2. `Layout::copy_table` omits the `depth > 1 && depth_pitch < slice_bytes` overlap validation enforced by `Layout::detile` / `Layout::tile`. 3. `config::default_dir` does not filter empty `LOCALAPPDATA`, `XDG_CACHE_HOME`, or `HOME` values, producing relative paths in the current working directory. ## Evidence (`file:line` & Code Proof) ### 1. Out-of-Bounds Panic in `Layout::copy_table` on `render_xor` Layouts - **`crates/victory-formats/src/texture.rs:548-558, 576-599, 653-658, 958-996`:** For `SW_64KB_R_X` (`d.swizzle.xor() == true`), `Layout::tiled` leaves `self.pattern = &EMPTY_PATTERN` (`[Vec::new(); 3]`). `Layout::configure_render_xor` sets `self.render_xor = Some(config)`, causing `Layout::addressable()` (`texture.rs:597-599`) to return `true`. `Layout::offset` (`628`) and `Layout::walk` (`774`) handle `self.render_xor`, whereas `Layout::copy_table` (`958-996`) skips checking `self.render_xor` and calls `self.column(m, 0)` (`657`), which indexes `self.pattern[0][(x % bw) as usize]` on an empty `Vec` and panics. `crates/victory-gpu/src/detile.rs:758` calls `layout.copy_table(...)` expecting `Err(_)` to map to `Why::NoTable` and fall back to CPU detiling. ### 2. Missing 3D Depth-Slice Overlap Check in `Layout::copy_table` - **`crates/victory-formats/src/texture.rs:963-971` vs `751-764` (`Layout::walk`):** `Layout::walk` rejects overlapping depth slices with `if depth > 1 && depth_pitch < slice_bytes { return Err(Error::TooSmall); }`. `Layout::copy_table` (whose doc promises *"The same checks as the detile"*) omits this check, allowing `depth > 1` with `depth_pitch < slice_bytes` (including `depth_pitch == 0`) to return overlapping `CopyRow::linear` offsets. ### 3. Empty Env Vars Produce Relative Paths in `config::default_dir` - **`crates/victory-core/src/config.rs:146-156` (`default_dir`):** Every other env helper in `config.rs` (`env_path:81`, `explicit_config_path:125`, `home_override:141`) filters empty strings via `.filter(|v| !v.is_empty())`, whereas `default_dir` calls `std::env::var_os("LOCALAPPDATA")`, `std::env::var_os("XDG_CACHE_HOME")`, and `std::env::var_os("HOME")` without filtering empty values (violating the XDG Base Directory spec and creating relative `victory/cache` / `.cache/victory/cache` paths in CWD). ## Impact - `copy_table` panics instead of falling back to CPU detiling when given a `render_xor` layout, and silently produces corrupt overlapping 3D `CopyTable`s when `depth_pitch < slice_bytes`. - Empty `LOCALAPPDATA`/`XDG_CACHE_HOME`/`HOME` causes `default_dir` to resolve inside CWD (failing `ensure_outside_repo` when run from the repo or polluting CWD). ## AI-Ready Fix Specification 1. In `crates/victory-formats/src/texture.rs` (`Layout::copy_table`): - Return `Err(Error::Unsupported)` if `!self.addressable() || self.render_xor.is_some()`. - Compute `slice_bytes` and enforce `if depth > 1 && depth_pitch < slice_bytes { return Err(Error::TooSmall); }`, matching `Layout::walk`. 2. In `crates/victory-core/src/config.rs` (`default_dir`), filter empty env values with `.filter(|v| !v.is_empty())` for `LOCALAPPDATA`, `XDG_CACHE_HOME`, and `HOME`. 3. Add unit tests in `victory-formats` (for `render_xor` -> `Err(Error::Unsupported)` and overlapping 3D `depth_pitch` -> `Err(Error::TooSmall)`) and `victory-core` (for empty `LOCALAPPDATA`/`XDG_CACHE_HOME`/`HOME`), and verify with `cargo test --locked -p victory-formats -p victory-core`.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-02 09:15:39 +00:00
Author
Owner

@⁠github-actions[bot] on GitHub · 2026-12-02 09:14 UTC · original

Please attach both logs from the run that went wrong so we can investigate without guessing. Paste %LOCALAPPDATA% into the File Explorer address bar to find them:

  1. Play log in %LOCALAPPDATA%\victory\logs\: the newest .log from that run (the console prints its path at startup on the Log: ... line).
  2. Crash log: %LOCALAPPDATA%\victory\data\<TitleId>\crashes.log, and if present, the newest .crash.log in %LOCALAPPDATA%\victory\data\<TitleId>\temp\.

Please also include:

  • GPU & VRAM, Windows version (10 or 11)
  • MiniVI preset / launcher flags (play-minivi.ps1 preset, DLSS/FG/RT, custom VICTORY_* vars) and commit SHA

(Clean-room policy: please only attach text logs/screenshots — do not upload copyrighted game files or executables.)

**@⁠github-actions[bot]** on GitHub · 2026-12-02 09:14 UTC · [original](https://github.com/Androtim/MiniVI/issues/320#issuecomment-7340588944) Please attach both logs from the run that went wrong so we can investigate without guessing. Paste `%LOCALAPPDATA%` into the File Explorer address bar to find them: 1. **Play log** in `%LOCALAPPDATA%\victory\logs\`: the newest `.log` from that run (the console prints its path at startup on the `Log: ...` line). 2. **Crash log**: `%LOCALAPPDATA%\victory\data\<TitleId>\crashes.log`, and if present, the newest `.crash.log` in `%LOCALAPPDATA%\victory\data\<TitleId>\temp\`. Please also include: - **GPU & VRAM**, **Windows version** (10 or 11) - **MiniVI preset / launcher flags** (`play-minivi.ps1` preset, DLSS/FG/RT, custom `VICTORY_*` vars) and **commit SHA** *(Clean-room policy: please only attach text logs/screenshots — do not upload copyrighted game files or executables.)*
This discussion has been locked. Commenting is limited to contributors.
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/Androtim--MiniVI#320
No description provided.