Skip to content

rustc (and cargo) handle non-utf-8 paths very poorly #39796

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

Closed
djzin opened this issue Feb 13, 2017 · 4 comments
Closed

rustc (and cargo) handle non-utf-8 paths very poorly #39796

djzin opened this issue Feb 13, 2017 · 4 comments
Labels
T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@djzin
Copy link
Contributor

djzin commented Feb 13, 2017

Considering rust goes through all these pains to have separate types such as OsString and OsStr and Path and CString vs just plain old String, precisely to distinguish between those strings that contain utf-8 and those that don't, it is very unfortunate that neither rustc, nor cargo, nor the build system, nor anything really can handle non-utf-8 paths. To replicate:

$ mkdir $'\377'
$ cd $'\377'
$ cargo new project
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Utf8Error { valid_up_to: 48 }', ../src/libcore/result.rs:837
note: Run with `RUST_BACKTRACE=1` for a backtrace.
$ cat << EOF > main.rs
> fn main() {
>     println!("hello, world!");
> }
> EOF
$ rustc main.rs
error: internal compiler error: unexpected panic

note: the compiler unexpectedly panicked. this is a bug.

note: we would appreciate a bug report: https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md#bug-reports

thread 'rustc' panicked at 'called `Option::unwrap()` on a `None` value', /buildslave/rust-buildbot/slave/stable-dist-rustc-linux/build/src/libcore/option.rs:323
note: Run with `RUST_BACKTRACE=1` for a backtrace.
@brson
Copy link
Contributor

brson commented Feb 14, 2017

The thing to do here is probably go over these projects and at least make sure they are converting all user-input paths to UTF-8 in a way that is reported as an error. Actually making everything everything work with non-utf-8 paths is probably quite a task, and maybe not worth it. Furthermore, it may not even be desirable to support non-UTF-8 paths for the can of support worms that opens up.

@brson brson added T-tools T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Feb 14, 2017
@cuviper
Copy link
Member

cuviper commented Feb 17, 2017

There's an old bug on this already which I can't find, but I know looked into it once. rustc_driver::main calls env::args(), and that Args iterator panics if it encounters invalid unicode.

@Mark-Simulacrum
Copy link
Member

This is a duplicate of #15890.

@cuviper
Copy link
Member

cuviper commented Apr 30, 2017

Aha, that's the bug I was trying to remember, and I'd even commented on it! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

4 participants