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

Merged
marquezinii merged 1 commit from upstream-pr/373 into main 2026-11-25 00:10:49 +00:00
marquezinii commented 2026-11-24 02:43:10 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by marquezinii on 2026-11-24T02:43:10Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:issue:6573423426 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/373). Originally posted by [marquezinii](https://github.com/marquezinii) on 2026-11-24T02:43:10Z. --- `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.
jeremygold02 commented 2026-11-24 06:55:38 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by jeremygold02 on 2026-11-24T04:09:07Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7121753961 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/373#issuecomment-7121753961). Originally posted by [jeremygold02](https://github.com/jeremygold02) on 2026-11-24T04:09:07Z. --- 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.
mercuryVM commented 2026-11-24 09:05:26 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by mercuryVM on 2026-11-24T08:26:51Z.

Review: APPROVED


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

slice::from_raw_parts_mut(null, 0) is undefined behaviour, and debug builds' precondition check turns it into an abort inside an extern "system" function. Routing both entry points through title_buffer, which maps null to &mut [], lets copy_truncated handle the size query the way it already handles an empty buffer: return 0 with ERROR_INSUFFICIENT_BUFFER.

No issues found.

AI-assisted (Claude Code).

<!-- greyfinch-sync:Marvisak/VIctory:review:6035899568 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/373#pullrequestreview-6035899568). Originally posted by [mercuryVM](https://github.com/mercuryVM) on 2026-11-24T08:26:51Z. **Review:** APPROVED --- Tested c000581 on Windows 11, RTX 5070, MSVC: `cargo test --workspace --no-fail-fast` passes (265 passed, 0 failed), including `a_title_image_name_into_no_buffer`. `slice::from_raw_parts_mut(null, 0)` is undefined behaviour, and debug builds' precondition check turns it into an abort inside an `extern "system"` function. Routing both entry points through `title_buffer`, which maps null to `&mut []`, lets `copy_truncated` handle the size query the way it already handles an empty buffer: return 0 with `ERROR_INSUFFICIENT_BUFFER`. No issues found. AI-assisted (Claude Code).
upstream-sync closed this pull request 2026-11-25 01:03:32 +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!373
No description provided.