From cf94a100548ebccfb60b1461dff4aafb031b8e6c Mon Sep 17 00:00:00 2001 From: Charlie Marsh Date: Mon, 29 Jul 2024 15:00:19 -0400 Subject: [PATCH] Skip copying to empty entries in seekable zip (#5571) ## Summary We cannot do this when streaming, since we may not have the metadata for the entry. Closes https://github.com/astral-sh/uv/issues/5565. --- crates/uv-extract/src/sync.rs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/crates/uv-extract/src/sync.rs b/crates/uv-extract/src/sync.rs index bcf13a5a0..4460d7974 100644 --- a/crates/uv-extract/src/sync.rs +++ b/crates/uv-extract/src/sync.rs @@ -48,12 +48,14 @@ pub fn unzip( // Copy the file contents. let outfile = fs_err::File::create(&path)?; let size = file.size(); - let mut writer = if let Ok(size) = usize::try_from(size) { - std::io::BufWriter::with_capacity(std::cmp::min(size, 1024 * 1024), outfile) - } else { - std::io::BufWriter::new(outfile) - }; - std::io::copy(&mut file, &mut writer)?; + if size > 0 { + let mut writer = if let Ok(size) = usize::try_from(size) { + std::io::BufWriter::with_capacity(std::cmp::min(size, 1024 * 1024), outfile) + } else { + std::io::BufWriter::new(outfile) + }; + std::io::copy(&mut file, &mut writer)?; + } // See `uv_extract::stream::unzip`. For simplicity, this is identical with the code there except for being // sync.