Conversation
…NtCreateFile`. `CreateFileAtW` passes `NtCreateFile` a `UNICODE_STRING` built from an unterminated slice. That is valid, but Win32 paths (`RtlInitUnicodeString`, `RtlDosPathNameToNtPathName_U`) always leave a NUL right after the name, and some third-party endpoint-security products hook `NtCreateFile` and copy `ObjectName->Buffer` up to a NUL instead of `Length` bytes. With cap-std's directory-relative opens such a hook reads past the allocation, and the process crashes when the next page is inaccessible. We hit this in production on Windows machines with such a product installed, and carrying this change as a patch fixed it. Make `CreateFileAtW` take a NUL-terminated slice, with `Length` excluding the terminator and `MaximumLength` including it, as `RtlInitUnicodeString` does. `open_at`, its only caller, now appends the NUL once for both the `CreateFileW` and `CreateFileAtW` branches. The name the kernel sees is unchanged.
dongs0104
force-pushed
the
windows-nul-terminate-name
branch
from
October 3, 2026 08:11
6826a97 to
d73b15f
Compare
CreateFileAtW passes to NtCreateFileCreateFileAtW passes to NtCreateFile.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
CreateFileAtWpassesNtCreateFileaUNICODE_STRINGbuilt from an unterminated slice. That is valid, but Win32 paths (RtlInitUnicodeString,RtlDosPathNameToNtPathName_U) always leave a NUL right after the name, and some third-party endpoint-security products hookNtCreateFileand copyObjectName->Bufferup to a NUL instead ofLengthbytes. With cap-std's directory-relative opens such a hook reads past the allocation, and the process crashes when the next page is inaccessible. We hit this in production on Windows machines with such a product installed, and carrying this change as a patch fixed it.Make
CreateFileAtWtake a NUL-terminated slice, withLengthexcluding the terminator andMaximumLengthincluding it, asRtlInitUnicodeStringdoes.open_at, its only caller, now appends the NUL once for both theCreateFileWandCreateFileAtWbranches. The name the kernel sees is unchanged.