diff --git a/crates/clawhdf5-tools/src/check.rs b/crates/clawhdf5-tools/src/check.rs index b5dd3c5..8c56771 100644 --- a/crates/clawhdf5-tools/src/check.rs +++ b/crates/clawhdf5-tools/src/check.rs @@ -197,7 +197,23 @@ fn unopenable(path: &std::path::Path, out: &mut Out) -> std::io::Result { "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}")), }, }; diff --git a/crates/clawhdf5-tools/tests/h5rs_interop.rs b/crates/clawhdf5-tools/tests/h5rs_interop.rs index 1669beb..7d97cc5 100644 --- a/crates/clawhdf5-tools/tests/h5rs_interop.rs +++ b/crates/clawhdf5-tools/tests/h5rs_interop.rs @@ -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}" ); }