only warn if CRC appears to be missing (#12722)

an alternative to #12706 

fixes #12694
This commit is contained in:
Aria Desires 2025-04-07 13:49:05 -04:00 committed by GitHub
parent 2f297b179d
commit c0ed5693a7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 26 additions and 4 deletions

1
Cargo.lock generated
View file

@ -5348,6 +5348,7 @@ dependencies = [
"thiserror 2.0.12",
"tokio",
"tokio-util",
"tracing",
"uv-distribution-filename",
"uv-normalize",
"uv-pypi-types",

View file

@ -92,11 +92,21 @@ pub async fn unzip<R: tokio::io::AsyncRead + Unpin>(
let computed = reader.compute_hash();
let expected = reader.entry().crc32();
if computed != expected {
return Err(Error::BadCrc32 {
let error = Error::BadCrc32 {
path: relpath,
computed,
expected,
});
};
// There are some cases where we fail to get a proper CRC.
// This is probably connected to out-of-line data descriptors
// which are problematic to access in a streaming context.
// In those cases the CRC seems to reliably be stubbed inline as 0,
// so we downgrade this to a (hidden-by-default) warning.
if expected == 0 {
warn!("presumed missing CRC: {error}");
} else {
return Err(error);
}
}
}

View file

@ -23,6 +23,7 @@ futures = { workspace = true }
thiserror = { workspace = true }
tokio = { workspace = true }
tokio-util = { workspace = true }
tracing = { workspace = true }
zip = { workspace = true }
[lints]

View file

@ -258,11 +258,21 @@ pub async fn read_metadata_async_stream<R: futures::AsyncRead + Unpin>(
let computed = reader.compute_hash();
let expected = reader.entry().crc32();
if computed != expected {
return Err(Error::BadCrc32 {
let error = Error::BadCrc32 {
path,
computed,
expected,
});
};
// There are some cases where we fail to get a proper CRC.
// This is probably connected to out-of-line data descriptors
// which are problematic to access in a streaming context.
// In those cases the CRC seems to reliably be stubbed inline as 0,
// so we downgrade this to a (hidden-by-default) warning.
if expected == 0 {
tracing::warn!("presumed missing CRC: {error}");
} else {
return Err(error);
}
}
let metadata = ResolutionMetadata::parse_metadata(&contents)