Skip to content

Commit 6716964

Browse files
Avoid rebuilding a path into an absolute form (#21923)
Co-authored-by: William Woodruff <[email protected]> Signed-off-by: William Woodruff <[email protected]>
1 parent 4dd39e8 commit 6716964

1 file changed

Lines changed: 34 additions & 0 deletions

File tree

‎crates/uv-extract/src/archive_path.rs‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ impl SanitizedArchivePath {
4242
Component::CurDir => (),
4343
}
4444
}
45+
46+
// Rebuilding can turn a normal component like `C:module.py` into a Windows prefix.
47+
if let Some(Component::Prefix(_) | Component::RootDir) = path.components().next() {
48+
return Ok(None);
49+
}
50+
4551
Ok(Some(Self(path)))
4652
}
4753

@@ -109,6 +115,34 @@ mod tests {
109115
Ok(())
110116
}
111117

118+
#[test]
119+
#[cfg(windows)]
120+
fn archive_member_path_rejects_windows_prefixes() -> Result<(), Error> {
121+
for file_name in [
122+
"C:module.py",
123+
"C:/module.py",
124+
r"\module.py",
125+
r"\\server\share\module.py",
126+
r"\\?\C:\module.py",
127+
"package/../C:module.py",
128+
"package/../c:module.py",
129+
"package/../C:subdir/module.py",
130+
"package/../C:../module.py",
131+
"./C:module.py",
132+
"package/./C:module.py",
133+
"package//C:module.py",
134+
"package/C:module.py/.",
135+
r"package\..\C:module.py",
136+
] {
137+
assert_eq!(
138+
SanitizedArchivePath::from_archive_member(file_name)?,
139+
None,
140+
"archive member: {file_name:?}"
141+
);
142+
}
143+
Ok(())
144+
}
145+
112146
#[test]
113147
fn archive_member_path_rejects_invalid_names() {
114148
for file_name in ["", "module\0.py", "module\n.py", "module\t.py"] {

0 commit comments

Comments
 (0)