Skip to content

BUG: Reject an h5ebsd slice that is larger than the volume - #78

Closed
imikejackson wants to merge 1 commit into
BlueQuartzSoftware:developfrom
imikejackson:fix/h5ebsd-volume-slice-bounds
Closed

imikejackson wants to merge 1 commit into
BlueQuartzSoftware:developfrom
imikejackson:fix/h5ebsd-volume-slice-bounds

Conversation

@imikejackson

Copy link
Copy Markdown
Collaborator

Summary

H5AngVolumeReader::loadData() and H5CtfVolumeReader::loadData() place each slice in the volume starting at (volume size - slice size) / 2 in X and Y. The volume size is the caller's xpoints/ypoints, normally the XPoints/YPoints values in the .h5ebsd header (getDims()). The slice size comes from that slice's own header. Nothing checked that the slice fits.

  • A slice with more columns or rows than the volume gets a negative start. Its cells are written into the previous slice, and its rows wrap. For the first or last slice the writes go before the start or past the end of the allocated arrays (heap out-of-bounds write). loadData() returned 0.
  • This happens when the header's XPoints/YPoints is smaller than a slice: a file written by another tool, a damaged file, or a caller that passes smaller dimensions to loadData(). simplnx EbsdToH5Ebsd writes the largest slice size, so files it writes are not affected.
  • Both readers now fail before copying a slice that is larger than the volume. The message names the file, the slice index, the slice size and the volume size, for example: Slice 1 in file '/path/vol.h5ebsd' has 8 x 4 cells, which is larger than the volume size of 6 x 4 cells. Each slice must fit inside the volume size.
Code Reader Failure
-90050 H5AngVolumeReader A slice is larger than the volume
-77001 H5CtfVolumeReader A slice is larger than the volume
  • A slice smaller than the volume is still centered, with the surrounding cells left at zero. This is not changed on purpose: simplnx EbsdToH5Ebsd (and DREAM.3D 6) write the largest slice size as the volume size, so a stack with mixed slice sizes is a valid file that this reader must keep loading. A new test pins this behavior.

Overlap with #72

#72 (fix/h5ang_missing_slice_error) also changes H5AngVolumeReader::loadData(), a few lines above this change (the error code copied after reader->readFile() fails). The hunks do not overlap and the error codes do not collide (#72 uses -90040 to -90046). Either merge order works; if Git reports a conflict, keep both changes.

Test Plan

  • New test EbsdLib::ebsdlib::H5EbsdVolumeReader-SliceLargerThanVolume (in the new H5EbsdVolumeReaderTest.cpp) fails on develop and passes with this change. It writes a three-slice ANG volume and a three-slice CTF volume whose middle slice has two more columns than the header. On develop, loadData() returns 0 and the last cell of slice 0 holds the first cell of slice 1 (1000 == 23), for both ANG and CTF.
  • New test EbsdLib::ebsdlib::H5EbsdVolumeReader-SliceSmallerThanVolumeIsCentered passes on develop and with this change (the behavior is kept).
  • Linux x64, Release: full ctest suite passes, 431/431 (429 baseline + 2 new).

Related Issue

Related to BlueQuartzSoftware/simplnx#1882 (the ReadH5Ebsd "not verified" note on slice placement in the volume readers).

🤖 Generated with Claude Code

- H5AngVolumeReader::loadData and H5CtfVolumeReader::loadData center each
  slice in the volume at (volume - slice) / 2. A slice with more columns or
  rows than the volume got a negative start, so its cells were written into
  the previous slice, and past the start or end of the buffer for the first
  or last slice. loadData returned 0.
- Both readers now return a new error code (-90050 for ANG, -77001 for CTF)
  with a message naming the file, the slice index, the slice size and the
  volume size when a slice is larger than the volume.
- A slice smaller than the volume is still centered with zero padding:
  converters write the largest slice size as the volume size, so such
  files are valid.
- Add H5EbsdVolumeReaderTest with synthetic ANG and CTF volumes for both
  cases.

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/h5ebsd-volume-slice-bounds branch November 13, 2026 16:28
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