Skip to content
Open
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
23 changes: 17 additions & 6 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 @@ -27,7 +27,7 @@ rustls = { version = "0.23", default-features = false, features = ["ring"] }
semver = "1.0.27"
serde = { version = "1.0.228", features = ["derive"] }
serde_json = "1.0.145"
sha2 = "0.10.9"
sha2 = "0.11.1"
tar = "0.4.45"
tempfile = "3.23.0"
text-stub-library = "0.9.0"
Expand Down
54 changes: 53 additions & 1 deletion src/release.rs
Original file line number Diff line number Diff line change
Expand Up @@ -756,6 +756,49 @@ mod tests {
assert!(!should_strip(Path::new("tcl90.dll"), &unsigned));
assert!(!should_strip(Path::new("tcl9tk90.dll"), &unsigned));
}

#[test]
fn verifies_and_rewinds_llvm_archive() -> Result<()> {
let contents = vec![b'x'; 20_000];
let mut file = tempfile::tempfile()?;
file.write_all(&contents)?;
file.rewind()?;
let download = Download {
url: String::new(),
size: contents.len() as u64,
sha256: "42e8bc96b8eec8c4e5d503483ba0cb843ce95243c8ca8575ffc69cd25d12c61c".to_string(),
};

let mut file = verify_llvm_archive(file, &download)?;
let mut actual = Vec::new();
file.read_to_end(&mut actual)?;
assert_eq!(actual, contents);
Ok(())
}

#[test]
fn rejects_invalid_llvm_archive_size_or_digest() -> Result<()> {
let mut file = tempfile::tempfile()?;
file.write_all(b"abc")?;
file.rewind()?;
let mut download = Download {
url: String::new(),
size: 4,
sha256: String::new(),
};

assert!(
verify_llvm_archive(file.try_clone()?, &download)
.is_err_and(|error| error.to_string().contains("size mismatch"))
);

download.size = 3;
assert!(
verify_llvm_archive(file, &download)
.is_err_and(|error| error.to_string().contains("SHA-256 mismatch"))
);
Ok(())
}
}

/// Create an install-only .tar.gz archive from a .tar.zst archive.
Expand Down Expand Up @@ -876,7 +919,16 @@ fn verify_llvm_archive(mut file: std::fs::File, download: &Download) -> Result<s
);

let mut hasher = Sha256::new();
std::io::copy(&mut file, &mut hasher)?;
let mut buffer = [0; 8192];
loop {
let count = match file.read(&mut buffer) {
Ok(0) => break,
Ok(count) => count,
Err(error) if error.kind() == std::io::ErrorKind::Interrupted => continue,
Err(error) => return Err(error.into()),
};
hasher.update(&buffer[..count]);
}
let sha256 = hex::encode(hasher.finalize());
ensure!(
sha256 == download.sha256,
Expand Down
Loading