Kernel: GetModuleFileName of a title image into a null buffer #373

Manually merged
github merged 1 commit from gh-pr/373/head into gh-pr/373/base 2026-11-26 04:01:32 +00:00
Owner

@⁠marquezinii on GitHub · 2026-11-24 02:43 UTC · original
marquezinii:fix/module-file-name-null-buffer → main · +29 −8 · 1 files · 1 commits · merged 2026-11-25 00:10 UTC

GetModuleFileNameW/A for a title image built slice::from_raw_parts_mut(out, size) from the title's pointer. A slice may not start at null even when it is empty, so a size query like GetModuleFileNameW(module, NULL, 0) was undefined behaviour; in a debug build it is a failed precondition check inside an extern "system" function, which aborts the process (0xc0000409).

A null buffer is now treated as no buffer: nothing is written, the call returns 0 and sets ERROR_INSUFFICIENT_BUFFER, which is what copy_truncated already does for an empty one.

Tested: a new test asks for a title image's name with (NULL, 0) through both functions. Before the change the test binary aborts with 0xc0000409; now both return 0 and the last error is 122. cargo test -p victory-hle passes and clippy reports nothing new.

This touches the two call sites only, not copy_truncated, so it should not get in the way of #186.

**@⁠marquezinii** on GitHub · 2026-11-24 02:43 UTC · [original](https://github.com/Marvisak/VIctory/pull/373) `marquezinii:fix/module-file-name-null-buffer` → `main` · +29 −8 · 1 files · 1 commits · merged 2026-11-25 00:10 UTC `GetModuleFileNameW`/`A` for a title image built `slice::from_raw_parts_mut(out, size)` from the title's pointer. A slice may not start at null even when it is empty, so a size query like `GetModuleFileNameW(module, NULL, 0)` was undefined behaviour; in a debug build it is a failed precondition check inside an `extern "system"` function, which aborts the process (0xc0000409). A null buffer is now treated as no buffer: nothing is written, the call returns 0 and sets `ERROR_INSUFFICIENT_BUFFER`, which is what `copy_truncated` already does for an empty one. Tested: a new test asks for a title image's name with `(NULL, 0)` through both functions. Before the change the test binary aborts with 0xc0000409; now both return 0 and the last error is 122. `cargo test -p victory-hle` passes and clippy reports nothing new. This touches the two call sites only, not `copy_truncated`, so it should not get in the way of #186.
A slice may not start at null, even an empty one, so asking for a title
image's name with (NULL, 0) was undefined behaviour; a debug build
aborted the process. A null buffer is now no buffer: nothing is written,
0 is returned and the last error is ERROR_INSUFFICIENT_BUFFER.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:01:29 +00:00
github manually merged commit c000581df2 into gh-pr/373/base 2026-11-26 04:01:32 +00:00
Author
Owner

@⁠jeremygold02 on GitHub · 2026-11-24 04:09 UTC · original

Thanks @⁠marquezinii for this null-buffer fix. I tested head c000581df2cf12aaadfe49025f9abba8b5993c8e with:

cargo test --locked -p victory-hle --lib a_title_image_name_into_no_buffer -- --test-threads=1

Result: 1 passed, 0 failed (86 filtered out). The regression test calls both GetModuleFileNameW and GetModuleFileNameA for a title image with (NULL, 0) and verifies the no-buffer error behavior, covering the path that previously formed a slice from a null pointer.

**@⁠jeremygold02** on GitHub · 2026-11-24 04:09 UTC · [original](https://github.com/Marvisak/VIctory/pull/373#issuecomment-7121753961) Thanks @⁠marquezinii for this null-buffer fix. I tested head `c000581df2cf12aaadfe49025f9abba8b5993c8e` with: ``` cargo test --locked -p victory-hle --lib a_title_image_name_into_no_buffer -- --test-threads=1 ``` Result: 1 passed, 0 failed (86 filtered out). The regression test calls both `GetModuleFileNameW` and `GetModuleFileNameA` for a title image with `(NULL, 0)` and verifies the no-buffer error behavior, covering the path that previously formed a slice from a null pointer.
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!373
No description provided.