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

Cannot compile a file in a non-utf8 directory #15890

Closed
alexcrichton opened this issue Jul 22, 2014 · 8 comments · Fixed by #42092
Closed

Cannot compile a file in a non-utf8 directory #15890

alexcrichton opened this issue Jul 22, 2014 · 8 comments · Fixed by #42092
Labels
A-driver Area: rustc_driver that ties everything together into the `rustc` compiler

Comments

@alexcrichton
Copy link
Member

$ mkdir $(echo 'foo\xff') 
$ touch $(echo 'foo\xff')/foo.rs
$ rustc $(echo 'foo\xff')/foo.rs
error: couldn't read foo�/foo.rs: couldn't open file (no such file or directory (No such file or directory); path=foo�/foo.rs; mode=open; access=read)
@frewsxcv
Copy link
Member

frewsxcv commented Feb 2, 2015

I was able to perform the commands above successfully with both fish and bash

fish

/tmp $ mkdir (echo 'foo\xff')
/tmp $ touch (echo 'foo\xff')/foo.rs
/tmp $ echo "fn main() {}" > (echo 'foo\xff')/foo.rs
/tmp $ rustc (echo 'foo\xff')/foo.rs

bash

/tmp $ mkdir $(echo 'foo\xff')
/tmp $ touch $(echo 'foo\xff')/foo.rs
/tmp $ echo "fn main() {}" > $(echo 'foo\xff')/foo.rs
/tmp $ rustc $(echo 'foo\xff')/foo.rs

@steveklabnik
Copy link
Member

I am able to as well. Closing! Thanks for the triage.

@alexcrichton
Copy link
Member Author

Hm I'm actually quite surprised that this works. What versions of the compilers were you using? For me it continues to not work:

$ mkdir $(echo 'foo\xff')    
$ touch $(echo 'foo\xff')/foo.rs 
$ rustc $(echo 'foo\xff')/foo.rs 
error: couldn't read "foo\u{fffd}/foo.rs": couldn't open path as file (no such file or directory (No such file or directory); path=foo�/foo.rs; mode=open; access=read)
$ rustc -V
rustc 1.0.0-nightly (1d00c545e 2015-01-30 19:56:34 +0000)

@frewsxcv
Copy link
Member

frewsxcv commented Feb 2, 2015

rustc 1.0.0-nightly (1d00c545e 2015-01-30 19:56:34 +0000)

@alexcrichton
Copy link
Member Author

Oh this may be a shell thing (I'm using zsh), when running ls after executing the commands in bash I see:

$ ls
foo\xff

I think that the escape syntax for bash must be different.

@alexcrichton alexcrichton reopened this Feb 2, 2015
@frewsxcv
Copy link
Member

frewsxcv commented Feb 2, 2015

I just tried zsh and got your error:

error: couldn't read "foo\u{fffd}/foo.rs": couldn't open path as file (no such file or directory (No such file or directory); path=foo�/foo.rs; mode=open; access=read)

@ebfe
Copy link
Contributor

ebfe commented Feb 2, 2015

Reproducable in bash (note the -e).

$ mkdir $(echo -e 'foo\xff')
$ touch $(echo -e 'foo\xff')/foo.rs
$ echo "fn main() {}" > $(echo -e 'foo\xff')/foo.rs
$ rustc $(echo -e 'foo\xff')/foo.rs
error: couldn't read "foo\u{fffd}/foo.rs": couldn't open path as file (no such file or directory (No such file or directory); path=foo�/foo.rs; mode=open; access=read)

@cuviper
Copy link
Member

cuviper commented Feb 28, 2016

It now fails saying, "called Result::unwrap() on an Err value". I believe this is simply due to rustc_driver::main() using env::args() rather than env::args_os(), so it panics on the non-utf8. You can reproduce this with any bad argument at all, e.g. in bash:

$ rustc $'\xff'
thread '<main>' panicked at 'called `Result::unwrap()` on an `Err` value: "\u{fffd}"', ../src/libcore/result.rs:746
note: Run with `RUST_BACKTRACE=1` for a backtrace.

Accepting OsString will require changes down through the getopts crate, and I guess all the other users of that should be updated too. I'm interested to try, if this sounds ok...

cuviper added a commit to cuviper/rust that referenced this issue May 18, 2017
Previously, any non-Unicode argument would panic rustc:

```
$ rustc $'foo\x80bar'
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 `Result::unwrap()` on an `Err` value:
"foo�bar"', /checkout/src/libcore/result.rs:859 note: Run with
`RUST_BACKTRACE=1` for a backtrace.
```

Now it gives a clean error:

```
$ rustc $'foo\x80bar'
error: Argument 1 is not valid Unicode: "foo�bar"
```

Maybe fixes rust-lang#15890, although we still can't *compile* arbitrary file names.
Mark-Simulacrum added a commit to Mark-Simulacrum/rust that referenced this issue May 19, 2017
Give a nicer error for non-Unicode arguments to rustc and rustdoc

Previously, any non-Unicode argument would panic rustc:

```
$ rustc $'foo\x80bar'
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 `Result::unwrap()` on an `Err` value:
"foo�bar"', /checkout/src/libcore/result.rs:859 note: Run with
`RUST_BACKTRACE=1` for a backtrace.
```

Now it gives a clean error:

```
$ rustc $'foo\x80bar'
error: Argument 1 is not valid Unicode: "foo�bar"
```

Maybe fixes rust-lang#15890, although we still can't *compile* arbitrary file names.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-driver Area: rustc_driver that ties everything together into the `rustc` compiler
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants