mirror of
https://github.com/astral-sh/uv.git
synced 2025-08-04 10:58:28 +00:00
Avoid allocating a max-size buffer (#1123)
This seems potentially-dangerous with no upside.
This commit is contained in:
parent
39021263dd
commit
f946d46273
1 changed files with 6 additions and 3 deletions
|
@ -50,9 +50,12 @@ pub async fn unzip_no_seek<R: tokio::io::AsyncRead + Unpin>(
|
|||
fs_err::tokio::create_dir_all(parent).await?;
|
||||
}
|
||||
let file = fs_err::tokio::File::create(path).await?;
|
||||
let size =
|
||||
usize::try_from(entry.reader().entry().uncompressed_size()).unwrap_or(usize::MAX);
|
||||
let mut writer = tokio::io::BufWriter::with_capacity(size, file);
|
||||
let mut writer =
|
||||
if let Ok(size) = usize::try_from(entry.reader().entry().uncompressed_size()) {
|
||||
tokio::io::BufWriter::with_capacity(size, file)
|
||||
} else {
|
||||
tokio::io::BufWriter::new(file)
|
||||
};
|
||||
let mut reader = entry.reader_mut().compat();
|
||||
tokio::io::copy(&mut reader, &mut writer).await?;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue