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

Avoid setting permissions during tar extraction #11191

Merged
merged 1 commit into from
Feb 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ uv-workspace = { path = "crates/uv-workspace" }
anstream = { version = "0.6.15" }
anyhow = { version = "1.0.89" }
arcstr = { version = "1.2.0" }
astral-tokio-tar = { git = "https://github.com/astral-sh/tokio-tar", rev = "c06006a2cf6a6ca42e11775ddf1502dee8a8c688" }
astral-tokio-tar = { git = "https://github.com/astral-sh/tokio-tar", rev = "ba2b140f27d081c463335f0d68b5f8df8e6c845e" }
async-channel = { version = "2.3.1" }
async-compression = { version = "0.4.12", features = ["bzip2", "gzip", "xz", "zstd"] }
async-trait = { version = "0.1.82" }
Expand Down
22 changes: 5 additions & 17 deletions crates/uv-extract/src/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use std::pin::Pin;

use futures::StreamExt;
use rustc_hash::FxHashSet;
use tokio_tar::EntryType;
use tokio_util::compat::{FuturesAsyncReadCompatExt, TokioAsyncReadCompatExt};
use tracing::warn;

Expand Down Expand Up @@ -150,10 +149,6 @@ async fn untar_in(
// Memoize filesystem calls to canonicalize paths.
let mut memo = FxHashSet::default();

// Delay any directory entries until the end, to ensure that directory permissions do not
// interfere with descendant extraction.
let mut directories = Vec::new();

let mut entries = archive.entries()?;
let mut pinned = Pin::new(&mut entries);
while let Some(entry) = pinned.next().await {
Expand All @@ -170,12 +165,6 @@ async fn untar_in(
continue;
}

// Defer the creation of any directory entries.
if file.header().entry_type() == EntryType::Directory {
directories.push(file);
continue;
}

// Unpack the file into the destination directory.
#[cfg_attr(not(unix), allow(unused_variables))]
let unpacked_at = file.unpack_in_memo(&dst, &mut memo).await?;
Expand Down Expand Up @@ -206,12 +195,6 @@ async fn untar_in(
}
}

// Create any deferred directories in topological order.
directories.sort_by(|a, b| b.path_bytes().cmp(&a.path_bytes()));
for mut dir in directories {
dir.unpack_in_memo(&dst, &mut memo).await?;
}
Copy link
Member Author

Choose a reason for hiding this comment

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

None of this matters now that we aren't setting permissions.


Ok(())
}

Expand All @@ -229,6 +212,7 @@ pub async fn untar_gz<R: tokio::io::AsyncRead + Unpin>(
&mut decompressed_bytes as &mut (dyn tokio::io::AsyncRead + Unpin),
)
.set_preserve_mtime(false)
.set_preserve_permissions(false)
.build();
Ok(untar_in(archive, target.as_ref()).await?)
}
Expand All @@ -247,6 +231,7 @@ pub async fn untar_bz2<R: tokio::io::AsyncRead + Unpin>(
&mut decompressed_bytes as &mut (dyn tokio::io::AsyncRead + Unpin),
)
.set_preserve_mtime(false)
.set_preserve_permissions(false)
.build();
Ok(untar_in(archive, target.as_ref()).await?)
}
Expand All @@ -265,6 +250,7 @@ pub async fn untar_zst<R: tokio::io::AsyncRead + Unpin>(
&mut decompressed_bytes as &mut (dyn tokio::io::AsyncRead + Unpin),
)
.set_preserve_mtime(false)
.set_preserve_permissions(false)
.build();
Ok(untar_in(archive, target.as_ref()).await?)
}
Expand All @@ -283,6 +269,7 @@ pub async fn untar_xz<R: tokio::io::AsyncRead + Unpin>(
&mut decompressed_bytes as &mut (dyn tokio::io::AsyncRead + Unpin),
)
.set_preserve_mtime(false)
.set_preserve_permissions(false)
.build();
untar_in(archive, target.as_ref()).await?;
Ok(())
Expand All @@ -300,6 +287,7 @@ pub async fn untar<R: tokio::io::AsyncRead + Unpin>(
let archive =
tokio_tar::ArchiveBuilder::new(&mut reader as &mut (dyn tokio::io::AsyncRead + Unpin))
.set_preserve_mtime(false)
.set_preserve_permissions(false)
.build();
untar_in(archive, target.as_ref()).await?;
Ok(())
Expand Down
Loading