fix(tools): h5rs check says why the library refused a file
With the header checks merged, the library refuses truncated files and misaligned chunk-index keys itself, so check reported only "file cannot be opened" for a truncated file. It now reports the truncation (stored end of file vs file length) or the library's error, and the misaligned chunk test accepts the library's refusal of the key. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
This commit is contained in:
@@ -197,7 +197,23 @@ fn unopenable(path: &std::path::Path, out: &mut Out) -> std::io::Result<i32> {
|
||||
"no HDF5 signature at offset 0 or any power of two from 512".to_string(),
|
||||
),
|
||||
Ok(off) => match clawhdf5_format::superblock::Superblock::parse(&data[off..], 0) {
|
||||
Ok(_) => (off as u64, "file cannot be opened".to_string()),
|
||||
Ok(sb) => match sb.data_end(off as u64, data.len() as u64) {
|
||||
Err(clawhdf5_format::error::FormatError::TruncatedFile {
|
||||
stored_eof,
|
||||
actual_len,
|
||||
}) => (
|
||||
0,
|
||||
format!(
|
||||
"file is truncated: the superblock's end-of-file address is \
|
||||
{stored_eof:#x} but the file is {actual_len:#x} bytes long"
|
||||
),
|
||||
),
|
||||
// Say what the library refused, not just that it did.
|
||||
_ => match clawhdf5::File::from_bytes(data.clone()) {
|
||||
Err(e) => (off as u64, format!("file cannot be opened: {e}")),
|
||||
Ok(_) => (off as u64, "file cannot be opened".to_string()),
|
||||
},
|
||||
},
|
||||
Err(e) => (off as u64, format!("superblock: {e}")),
|
||||
},
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user