Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Windows: OsStr need not be valid UTF-8 #56171

Closed
DemiMarie opened this issue Nov 22, 2018 · 4 comments
Closed

Windows: OsStr need not be valid UTF-8 #56171

DemiMarie opened this issue Nov 22, 2018 · 4 comments
Labels
A-docs Area: Documentation for any part of the project, including the compiler, standard library, and tools O-windows Operating system: Windows

Comments

@DemiMarie
Copy link
Contributor

DemiMarie commented Nov 22, 2018

On Windows, filenames (and many other strings) are stored in UCS-2, not UTF-8. This corresponds to WTF-8, not UTF-8. Furthermore, the NT kernel uses length-specified strings via the UNICODE_STRING struct, and uses only \ as the path separator. Therefore, many APIs (such as NtCreateFile and NtCreateKey) actually allow NUL characters in names. While the NTFS driver does not allow NUL to be part of a filename, registry keys can have NUL characters in there names.

Therefore, I propose that OsStr on Windows be able to be created from any valid WTF-8, and that an API be provided that allows them to be created with NUL characters.

Also see #53261 (comment)

@ollie27
Copy link
Member

ollie27 commented Nov 22, 2018

Are OsStrExt and OsStringExt in std::os::windows::ffi not sufficient?

@retep998
Copy link
Member

OsStr literally already is this. It stores WTF-8 instead of UTF-8 and is capable of holding NUL characters just fine.

@estebank estebank added O-windows Operating system: Windows A-docs Area: Documentation for any part of the project, including the compiler, standard library, and tools labels Jan 11, 2019
@estebank
Copy link
Contributor

Leaving open as under the purview of @rust-lang/docs, like #53261.

@Mark-Simulacrum
Copy link
Member

Closing since this seems to be satisfied by the existing APIs (per above comments and reading the API docs today). #53261 touches on the more specific issue of std::ffi docs being misleading about the underlying representation of OsString on Windows, but that's an orthogonal and separate concern.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-docs Area: Documentation for any part of the project, including the compiler, standard library, and tools O-windows Operating system: Windows
Projects
None yet
Development

No branches or pull requests

5 participants