cksum: Don't panic when checked file returned EIO (#10534)

This commit is contained in:
oech3
2026-01-30 02:15:19 -08:00
committed by GitHub
parent e6e2b28462
commit 12193c52c6
2 changed files with 34 additions and 2 deletions
@@ -676,8 +676,26 @@ fn compute_and_check_digest_from_file(
// TODO: improve function signature to use ReadingMode instead of binary bool
// Set binary to false because --binary is not supported with --check
let (calculated_checksum, _) =
digest_reader(&mut digest, &mut file_reader, /* binary */ false).unwrap();
let (calculated_checksum, _) = match digest_reader(&mut digest, &mut file_reader, false) {
Ok(result) => result,
Err(err) => {
show!(err.map_err_context(|| {
locale_aware_escape_name(&real_filename_to_check, QuotingStyle::SHELL_ESCAPE)
.to_string_lossy()
.to_string()
}));
write_file_report(
std::io::stdout(),
filename,
FileChecksumResult::CantOpen,
prefix,
opts.verbose,
);
return Err(LineCheckError::CantOpenFile);
}
};
// Do the checksum validation
let checksum_correct = match calculated_checksum {
+14
View File
@@ -3046,3 +3046,17 @@ mod debug_flag {
.stderr_contains("pclmul");
}
}
#[test]
#[cfg(all(target_os = "linux", not(target_env = "musl")))]
fn test_check_file_with_io_error() {
// /proc/self/mem causes EIO when read without proper seeking
new_ucmd!()
.arg("-a")
.arg("md5")
.arg("--check")
.pipe_in("d8e8fca2dc0f896fd7cb4cb0031ba249 /proc/self/mem\n")
.fails()
.stderr_contains("Input/output error")
.stdout_contains("FAILED open or read");
}