mirror of
https://github.com/astral-sh/uv.git
synced 2025-11-17 02:52:45 +00:00
Allow more trailing null bytes in zip files (#15452)
## Summary There isn't any risk here, and we have reports of at least one zip file with more than one (but fewer than, e.g., 10) null bytes. Closes https://github.com/astral-sh/uv/issues/15451.
This commit is contained in:
parent
3e34aee63e
commit
088c908cda
1 changed files with 16 additions and 10 deletions
|
|
@ -532,19 +532,25 @@ pub async fn unzip<R: tokio::io::AsyncRead + Unpin>(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Determine whether the reader is exhausted.
|
// Determine whether the reader is exhausted, but allow trailing null bytes, which some zip
|
||||||
|
// implementations incorrectly include.
|
||||||
if !skip_validation {
|
if !skip_validation {
|
||||||
let mut buffer = [0; 1];
|
let mut has_trailing_bytes = false;
|
||||||
if reader.read(&mut buffer).await.map_err(Error::Io)? > 0 {
|
let mut buf = [0u8; 256];
|
||||||
// If the buffer contains a single null byte, ignore it.
|
loop {
|
||||||
if buffer[0] == 0 {
|
let n = reader.read(&mut buf).await.map_err(Error::Io)?;
|
||||||
if reader.read(&mut buffer).await.map_err(Error::Io)? > 0 {
|
if n == 0 {
|
||||||
|
if has_trailing_bytes {
|
||||||
|
warn!("Ignoring trailing null bytes in ZIP archive");
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
for &b in &buf[..n] {
|
||||||
|
if b == 0 {
|
||||||
|
has_trailing_bytes = true;
|
||||||
|
} else {
|
||||||
return Err(Error::TrailingContents);
|
return Err(Error::TrailingContents);
|
||||||
}
|
}
|
||||||
|
|
||||||
warn!("Ignoring trailing null byte in ZIP archive");
|
|
||||||
} else {
|
|
||||||
return Err(Error::TrailingContents);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue