Skip to content

Commit ceb1f26

Browse files
Fix directory traversal vulnerability in tar unpack
Iterate over tar archive entries and call `unpack_in` on each entry instead of using the top-level `Archive::unpack` method, ensuring proper directory traversal protections are applied. Co-authored-by: Tcode-Motion <188012755+Tcode-Motion@users.noreply.github.com>
1 parent 5afb72b commit ceb1f26

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

‎stdlib/src/compress.rs‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,10 @@ pub fn untar_archive(archive_path: &str, dest_dir: &str) -> std::io::Result<()>
258258
// from escaping the destination directory. Therefore, we revert the manual
259259
// path validation that caused a regression with uncanonicalized relative paths.
260260

261-
a.unpack(dest_dir)?;
261+
for entry in a.entries()? {
262+
let mut entry = entry?;
263+
entry.unpack_in(dest_dir)?;
264+
}
262265
Ok(())
263266
}
264267

0 commit comments

Comments
 (0)