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:
osobh
2026-09-26 01:46:48 -05:00
co-authored by Claude Opus 5.5
parent e60bde3579
commit 72306c6013
2 changed files with 21 additions and 2 deletions
+16
View File
@@ -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(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}")),
},
};
+4 -1
View File
@@ -741,8 +741,11 @@ fn check_flags_a_misaligned_chunk() {
let o = h5rs(&["check", &bad.to_string_lossy()]);
let s = stdout(&o);
assert_eq!(code(&o), 1, "{s}");
// The library's chunk-index reader refuses the key first (as libhdf5
// does); either way the problem is reported against the dataset.
assert!(
s.contains("/grp/gz: chunk at [103, 0] offset 103 in dimension 0 is not a multiple of the chunk size 100"),
s.contains("/grp/gz: chunk at [103, 0] offset 103 in dimension 0 is not a multiple of the chunk size 100")
|| s.contains("/grp/gz: chunk index (v1 B-tree): chunked read error: bad coordinate offset [103, 0] for chunk dimensions [100, 4]"),
"{s}"
);
}