Skip to content

BUG: Validate the pattern dataset in the Esprit and OIM HDF5 readers - #83

Closed
imikejackson wants to merge 1 commit into
BlueQuartzSoftware:developfrom
imikejackson:fix/h5-pattern-dataset-checks
Closed

imikejackson wants to merge 1 commit into
BlueQuartzSoftware:developfrom
imikejackson:fix/h5-pattern-dataset-checks

Conversation

@imikejackson

Copy link
Copy Markdown
Collaborator

Summary

H5EspritReader (RawPatterns) and H5OIMReader (Pattern) read the pattern dataset without validating it:

  • dims[1] and dims[2] were read even when the dataset has fewer than 3 dimensions (out-of-bounds std::vector access).
  • The first dimension was not compared with the scan's point count. A short dataset was accepted and the buffer was smaller than points x height x width; H5EspritReader::applyRasterOrder() and every caller then read past its end (the new test crashes with a bus error on develop).
  • The dataset type was not checked (a floating point dataset was converted to uint8).
  • The error from H5Lite::readPointerDataset() was ignored, so a failed read returned success.

Both readers now require a rank 3 integer dataset whose first dimension equals the scan's point count, and report a read failure. Each failure sets a new error code and a message that names the file, the scan and the dataset, for example H5EspritReader Error: The 'RawPatterns' dataset of scan 'Section_435' in file '<path>' holds 10 patterns but the scan has 360000 points (600 x 600). Files without a pattern dataset, or with a valid one, are read as before.

H5EspritReader H5OIMReader Failure
-90330 -90430 Pattern dataset is not rank 3
-90331 -90431 First dimension is not the scan's point count
-90332 -90432 Pattern dataset does not hold integers
-90333 -90433 Pattern dataset cannot be read

H5OIMReader::readFile() reports every readData() failure as -900022 and, on develop, replaced the message with an empty string. It now keeps the readData() message; this hunk is identical to the one in #70.

Merge order

#70 (issue69-reader-error-messages) rewrites the error-message handling in the same two files. Please merge #70 first. This branch follows its message style (std::stringstream + setErrorMessage(ss.str())), and its only change outside readData() is the same hunk #70 makes in H5OIMReader::readFile(). git merge-tree shows that this branch and #70 merge cleanly in either order. The new tests are in a new file so they do not conflict with the tests #70 appends to EdaxOIMReaderTest.cpp and H5EspritReaderTest.cpp.

Test Plan

  • New test EbsdLib::ebsdlib::H5PatternDatasetTest::{H5EspritReaderValidatesRawPatterns,H5OIMReaderValidatesPattern} (new file Source/Test/H5PatternDatasetTest.cpp) adds a synthetic pattern dataset to a copy of the Esprit and EDAX test scans: valid (N x 3 x 2 uint8), rank 2, 10 patterns only, float, and unreadable (external storage file that does not exist).
    • On develop: Esprit returns 0 for the rank 2 dataset (0 == -90330) and crashes with a bus error on the short dataset; OIM returns 0 for all four invalid datasets (0 == -900022).
    • With this change: each invalid dataset gives the expected code and message; the valid dataset is read and the patterns are placed with the scan's raster order (Esprit cells 30/31 swapped).
  • Linux x64, Release (ci-linux-x64 preset): full ctest suite, 431/431 passed.

Related Issue

Related to BlueQuartzSoftware/simplnx#1867 (class C07d, ReadH5EspritData.cpp:109, and item ReadH5OimDataFilter#4).

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

- H5EspritReader (RawPatterns) and H5OIMReader (Pattern) read dims[1] and
  dims[2] of the pattern dataset without checking its rank, did not check that
  it holds one pattern per scan point or that it holds integer pixels, and
  ignored the error from reading it. A short dataset was accepted and later
  code (raster reordering, callers) read past the end of the pattern buffer.
- Both readers now require a rank 3 dataset whose first dimension equals the
  scan's point count and whose type is integer, and report a read failure.
  Each failure sets a new error code and a message that names the file, the
  scan and the dataset (H5EspritReader -90330..-90333, H5OIMReader
  -90430..-90433). Valid files are read as before.
- H5OIMReader::readFile() keeps the readData() message when it reports
  -900022, as in BlueQuartzSoftware#70.
- New test H5PatternDatasetTest covers valid, rank 2, short, floating point
  and unreadable pattern datasets for both 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

@imikejackson
imikejackson deleted the fix/h5-pattern-dataset-checks branch November 13, 2026 16:27
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