Skip to content

Fix to_file_path for relative paths with drive letters#442

Open
matklad wants to merge 1 commit intoservo:mainfrom
matklad:paths-on-windows-are-hard
Open

Fix to_file_path for relative paths with drive letters#442
matklad wants to merge 1 commit intoservo:mainfrom
matklad:paths-on-windows-are-hard

Conversation

@matklad
Copy link
Copy Markdown

@matklad matklad commented Apr 3, 2018

Hi!

I've recently hit this debug assertion on windows for paths like file://C:.

I've added a couple of tests and a "fix", which just turns the assertion into error. I have no idea how to fix this properly.


This change is Reviewable

Comment thread tests/unit.rs
fn to_file_path_for_relative_windows_paths() {
if cfg!(windows) {
let url = Url::parse("file://example.com/C:foo").unwrap();
assert!(url.to_file_path().is_ok());
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

NB: unlike other tests, this is ok. I would think that it should be err as well, but std::Path disagrees with me and insists that \\exaple.com\C:foo is an absolute path. Is this a bug in stdlib maybe as well?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

@retep998 perhaps you know? Consider this program:

use std::path::PathBuf;

fn main() {
    let p1 = PathBuf::from(r"C:foo");
    let p2 = PathBuf::from(r"\\example.com\C:foo");
    println!("{} {}", p1.is_absolute(), p2.is_absolute());
}

It currently prints false true. Is this the correct behavior?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

C:foo is relative to the current directory for the C drive. \\example.com\C:foo is a UNC path which is absolute.

For more information on the types of paths... https://googleprojectzero.blogspot.com/2016/02/the-definitive-guide-on-win32-to-nt.html

@matklad
Copy link
Copy Markdown
Author

matklad commented Aug 29, 2018

ping @SimonSapin :-)

I don't feel a pressing need for this or anything, but this issue seems somewhat interesting, because it arguably allows to sneak in relative path in release build, which might be security sensitive?

@SimonSapin SimonSapin mentioned this pull request Oct 17, 2018
42 tasks
@bors-servo
Copy link
Copy Markdown
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants