zlacker

[parent] [thread] 4 comments
1. kragen+(OP)[view] [source] 2025-08-22 22:01:56
Isn't &[u8] what you should be using for command-line arguments and filenames and whatnot? In that case you'd want its name to be short, like &[u8], rather than long like &[bytes] or &[raw_uncut_byte] or something.
replies(1): >>adastr+7f
2. adastr+7f[view] [source] 2025-08-22 23:44:12
>>kragen+(OP)
OsStr/OsString is what you would use in those circumstances. Path/PathBuf specifically for filenames or paths, which I think uses OsStr/OsString internally. I've never looked at OsStr's internals but I wouldn't be surprised if it is a wrapper around &[u8].

Note that &[u8] would allow things like null bytes, and maybe other edge cases.

replies(1): >>kragen+mk
◧◩
3. kragen+mk[view] [source] [discussion] 2025-08-23 00:20:25
>>adastr+7f
You can't get null bytes from a command-line argument. And going by >>44991638 it's common to not use OsString when accepting command-line arguments, because std::env::args yields Strings, which means that probably most Rust programs that accept filenames on the command line have this bug.
replies(1): >>adastr+Mo
◧◩◪
4. adastr+Mo[view] [source] [discussion] 2025-08-23 01:03:08
>>kragen+mk
Rust String can contain null bytes! Rust uses explicit string lengths. Agree though that most OS wouldn't be able to pass null bytes in arguments though.
replies(1): >>kragen+wp
◧◩◪◨
5. kragen+wp[view] [source] [discussion] 2025-08-23 01:09:33
>>adastr+Mo
Right, but it can't contain invalid UTF-8, which is valid in both command-line parameters and in filenames on Linux, FreeBSD, and other normal Unixes. See my link above for a demonstration of how this causes bugs in Rust programs.
[go to top]