Skip to content

Add checks for Windows reserved filenames in cargo install process #8160

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
wants to merge 2 commits into from

Conversation

CPerezz
Copy link
Contributor

@CPerezz CPerezz commented Apr 26, 2020

Hi, my first PR here, so happy to get any advices if the code can be improved or something doesn't seem correct! 😄

Following issue #8055, added a block before the
unpacking stage of cargo install to check if any of
the paths that the package has, contains files or folders
with reserved Windows filenames.

  • Added an error message for these specific cases pointing which is
    the path an the file that are actually causing the error.

  • Added an error message for failed obtentions of the path as &str
    if the Path contains non-UTF8 characters which are non-valid Paths
    in Windows.

  • Added test for packages with a file/folder that has a reserved filename on
    Windows.

CPerezz added 2 commits April 26, 2020 12:42
Following issue rust-lang#8055, added a block before the
unpacking stage of `cargo install` to check if any of
the paths that the package has contains files or folders
with reserved Windows filenames.

- Added an error message for these specific cases pointing which is
the path an the file that are actually causing the error.

- Added an error message for failed obtentions of the path as &str
if the Path contains non-UTF8 characters which are non-valid Paths
in Windows.
Following rust-lang#8055 we need to propperly print errors if the
path to any file of the package contains a windows reserved filename.

- Added tests for packages with a file that has a reserved filename on
Windows.

- Added tests for packages with a folder that has a reserved
filaname on Windows.
@rust-highfive
Copy link

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @Eh2406 (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

Please see the contribution instructions for more information.

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Apr 26, 2020
Comment on lines +507 to +514
// If the path contains non UTF-8 characters, provide the
// propper error.
.ok_or(crate::util::errors::ProcessError {
desc: String::from("Invalid UTF8 character in the file path"),
exit: None,
output: None,
})
.chain_err(|| "Invalid UTF8 character in the file path")?
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know if that's needed, but It would be weird if the path contains a non-UTF-8 character and the process just panics pointing to the unwrap() that would replace this code.

If you feel that this should not be checked here, I can just unwrap() and that's it. (Or if you have better suggestions, happy to hear & apply them!)

@ehuss
Copy link
Contributor

ehuss commented Apr 26, 2020

Thanks for the PR! However, there seems to be one already open for this at #8136.

@CPerezz
Copy link
Contributor Author

CPerezz commented Apr 26, 2020

Oh.. didn't see the issue assigned to anyone so I decided to go for it.

My bad.. I guess this can be closed unless any of the checks I'm doing is not done on the other PR.

Thanks anyway and hope I can contribute on something else soon.

@bors
Copy link
Contributor

bors commented Apr 26, 2020

☔ The latest upstream changes (presumably #8136) made this pull request unmergeable. Please resolve the merge conflicts.

@ehuss
Copy link
Contributor

ehuss commented Apr 26, 2020

No worries, sorry for the confusion, thanks for taking a look, though!

@ehuss ehuss closed this Apr 26, 2020
@CPerezz CPerezz deleted the windows-reserved-filenames branch April 26, 2020 19:20
@CPerezz
Copy link
Contributor Author

CPerezz commented Apr 27, 2020

Hey @ehuss I'm a bit confused.

You mentioned that #8136 was already doing this, but after reviewing it now and making some tests with this commit merged, I realized it was not (as far as I've seen).

#8136 as far as I've seen is actually warning on cargo package calls, but for all of the crates that are already published with windows restricted filenames, it will keep failing when you call cargo install without mentioning the specific reason why.

My PR was indeed taking care of these already-published crates and outputing an error telling the user that indeed they were not possible to install with cargo install due to the usage of restricted filenames in Windows. Also the PR not only checks for filenames but also for the folder names. Which are also restricted.

Idk if you considered that it's not needed, in which case, it's totally fine,. Otherways, we can have explicit errors when using cargo install with crates that are already published and contain this reserved filenames.

Sorry for the inconvenience if this does not apply 😄

@CPerezz CPerezz restored the windows-reserved-filenames branch April 27, 2020 11:02
@ehuss
Copy link
Contributor

ehuss commented Apr 27, 2020

The extraction code path is the same for cargo package or cargo install. You should see an error like this:

target/debug/cargo install navi --version 2.2.0
    Updating crates.io index
  Downloaded navi v2.2.0
error: failed to unpack package `navi v2.2.0`

Caused by:
  failed to unpack entry at `navi-2.2.0/src/flows/aux.rs`

Caused by:
  `navi-2.2.0/src/flows/aux.rs` appears to contain a reserved Windows path, it cannot be extracted on Windows

Caused by:
  failed to unpack `C:\Users\User\.cargo\registry\src\github.com-1ecc6299db9ec823\navi-2.2.0\src\flows\aux.rs`

Caused by:
  failed to unpack `navi-2.2.0/src/flows/aux.rs` into `C:\Users\User\.cargo\registry\src\github.com-1ecc6299db9ec823\navi-2.2.0\src\flows\aux.rs`

Caused by:
  The system cannot find the file specified. (os error 2)

Notice that it says "aux.rs` appears to contain a reserved Windows path, it cannot be extracted on Windows". Are you not seeing that error? Are you sure you have the latest master? What is the exact commands that you are running and the exact error you are seeing?

@CPerezz
Copy link
Contributor Author

CPerezz commented Apr 27, 2020

That was my bad. Didn't had a Windows machine now to write the test to check it, and didn't know that the path was the same for both commands. So I raised the flag to early.

It should forget about this and look for other begginer issues to work on since all of this seems to be nor correctly handled everywhere.

Sorry for the inconvenience.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants