Skip to content

BUG: Reject an HDF5 lattice constants dataset that does not hold 6 values - #84

Closed
imikejackson wants to merge 1 commit into
BlueQuartzSoftware:developfrom
imikejackson:fix/h5-lattice-constants-length
Closed

imikejackson wants to merge 1 commit into
BlueQuartzSoftware:developfrom
imikejackson:fix/h5-lattice-constants-length

Conversation

@imikejackson

Copy link
Copy Markdown
Collaborator

Summary

The HDF5 phase readers accepted a lattice constants dataset of any length. H5AngReader, H5CtfReader and H5EspritReader read a phase's LatticeConstants dataset with READ_PHASE_HEADER_ARRAY, which stores whatever vector is in the file. Every caller indexes 6 values (a, b, c, alpha, beta, gamma), so a 2-element dataset was accepted and later read past its end, and a 7-element dataset was accepted silently.

  • A new macro READ_PHASE_LATTICE_CONSTANTS in EbsdMacros.h reads the dataset through READ_PHASE_HEADER_ARRAY and then rejects it when it does not hold exactly 6 values. The three readers use it in place of READ_PHASE_HEADER_ARRAY for the lattice constants only (Categories stays variable length).
  • H5AngVolumeReader::getPhases() and H5CtfVolumeReader::getPhases() now pass the file name to the slice reader that reads the phases, so the message names the file.
  • Files with 6 lattice constants are read as before.
Code Failure
-90350 The LatticeConstants dataset of a phase does not hold exactly 6 values

Example message: H5EspritReader Error: The 'LatticeConstants' dataset of phase '1' in file '<path>' holds 2 values but 6 (a, b, c, alpha, beta, gamma) are required.

Other HDF5 readers checked:

  • H5OIMReader reads six scalar datasets (Lattice Constant a ... gamma) into a 6-element vector, so the count is always 6.
  • H5OINAReader already rejects Lattice Dimensions / Lattice Angles with fewer than 3 values (-90031 / -90032) and builds the 6-element vector itself.

Not changed here: H5CtfReader::readFile() ignores the result of readHeader() (it keeps going to readData()); H5CtfVolumeReader::getPhases() prints to std::cout instead of setting an error. Both are separate defects.

Test Plan

  • New test EbsdLib::ebsdlib::H5LatticeConstantsTest::{H5AngReader,H5CtfReader,H5EspritReader} (new file Source/Test/H5LatticeConstantsTest.cpp) writes a slice with H5AngImporter / H5CtfImporter (or copies the Esprit test file), replaces phase 1's LatticeConstants with 2, 7 and 6 values and calls readHeaderOnly().
    • On develop: all three readers return success for 2 and 7 values (REQUIRE( err < 0 ) fails with 0 < 0, phase lattice constants count 2 / 7).
    • With this change: 2 and 7 values give -90350 with the message above; 6 values are read unchanged.
  • Linux x64, Release (ci-linux-x64 preset): full ctest suite, 432/432 passed.

Related Issue

Related to BlueQuartzSoftware/simplnx#1866 (items ReadH5EbsdFilter#4 and ReadH5EspritDataFilter#2).

Merge notes: no overlap in code with the open PRs. #72 changes H5AngVolumeReader::getPhases() a few lines below the added setFileName() call; both merge cleanly (checked with git merge-tree). The sibling PR for the pattern dataset checks (fix/h5-pattern-dataset-checks) also merges cleanly with this one.

The bluequartz-skills plugin skills were not available in this environment; the change follows the repository's .clang-format and coding standards.

🤖 Generated with Claude Code

…lues

- H5AngReader, H5CtfReader and H5EspritReader read a phase's LatticeConstants
  dataset with READ_PHASE_HEADER_ARRAY, which accepts a vector of any length.
  Callers index all 6 values (a, b, c, alpha, beta, gamma), so a short dataset
  was read past its end and a long one was silently accepted.
- The new READ_PHASE_LATTICE_CONSTANTS macro reads the dataset and returns
  error -90350 with a message that names the file, the phase and the number of
  values when the dataset does not hold exactly 6 values.
- H5AngVolumeReader and H5CtfVolumeReader pass the file name to the slice
  reader that reads the phases so that the message names the file.
- New test H5LatticeConstantsTest covers 2, 7 and 6 values for all three readers.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@imikejackson imikejackson mentioned this pull request Nov 13, 2026
7 tasks done
@imikejackson

Copy link
Copy Markdown
Collaborator Author

Closed in favor of #86, which merges this branch (with its history) together with the other open EbsdLib fixes for the next release, so simplnx can build against one EbsdLib branch. The branch is kept.

🤖 Generated with Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant