Skip to content

Commit 143c12f

Browse files
zaniebotzanieb
andauthored
Propagate errors when reading wheel entry points (#19794)
## Summary Prior to this change, reading `entry_points.txt` treated every failure as a missing file. Malformed metadata such as invalid UTF-8 therefore caused declared entry points to be silently omitted. This PR continues to allow missing entry-point metadata while propagating other read errors. ## Test plan - `cargo test -p uv-install-wheel invalid_utf8_entry_points` Co-authored-by: Zanie Blue <contact@zanie.dev>
1 parent b2d8307 commit 143c12f

1 file changed

Lines changed: 27 additions & 4 deletions

File tree

crates/uv-install-wheel/src/wheel.rs

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1059,8 +1059,12 @@ pub(crate) fn parse_scripts(
10591059
.join(format!("{dist_info_prefix}.dist-info/entry_points.txt"));
10601060

10611061
// Read the entry points mapping. If the file doesn't exist, we just return an empty mapping.
1062-
let Ok(ini) = fs::read_to_string(entry_points_path) else {
1063-
return Ok((Vec::new(), Vec::new()));
1062+
let ini = match fs::read_to_string(entry_points_path) {
1063+
Ok(ini) => ini,
1064+
Err(err) if err.kind() == io::ErrorKind::NotFound => {
1065+
return Ok((Vec::new(), Vec::new()));
1066+
}
1067+
Err(err) => return Err(err.into()),
10641068
};
10651069

10661070
scripts_from_ini(extras, python_minor, ini)
@@ -1099,7 +1103,7 @@ impl RenameOrCopy {
10991103

11001104
#[cfg(test)]
11011105
mod test {
1102-
use std::io::Cursor;
1106+
use std::io::{Cursor, ErrorKind};
11031107
use std::path::Path;
11041108

11051109
use anyhow::Result;
@@ -1108,7 +1112,7 @@ mod test {
11081112

11091113
use super::{
11101114
Error, RecordEntry, Script, WheelFile, format_shebang, get_script_executable,
1111-
parse_email_message_file, read_record, write_installer_metadata,
1115+
parse_email_message_file, parse_scripts, read_record, write_installer_metadata,
11121116
};
11131117

11141118
#[test]
@@ -1186,6 +1190,25 @@ mod test {
11861190
WheelFile::parse(&wheel_with_version("2.0")).unwrap_err();
11871191
}
11881192

1193+
#[test]
1194+
fn invalid_utf8_entry_points() -> Result<()> {
1195+
let wheel = assert_fs::TempDir::new()?;
1196+
wheel
1197+
.child("example-1.0.0.dist-info/entry_points.txt")
1198+
.write_binary(&[0xff])?;
1199+
1200+
let error = parse_scripts(&wheel, "example-1.0.0", None, 13)
1201+
.err()
1202+
.ok_or_else(|| anyhow::anyhow!("invalid UTF-8 should fail to parse"))?;
1203+
1204+
assert!(matches!(
1205+
error,
1206+
Error::Io(err) if err.kind() == ErrorKind::InvalidData
1207+
));
1208+
1209+
Ok(())
1210+
}
1211+
11891212
#[test]
11901213
fn record_with_absolute_paths() {
11911214
let record: &str = indoc! {"

0 commit comments

Comments
 (0)