Skip to content

BUG: Use one column count for a square-grid ANG file - #73

Closed
imikejackson wants to merge 1 commit into
BlueQuartzSoftware:developfrom
imikejackson:fix/ang_square_grid_columns
Closed

imikejackson wants to merge 1 commit into
BlueQuartzSoftware:developfrom
imikejackson:fix/ang_square_grid_columns

Conversation

@imikejackson

@imikejackson imikejackson commented Nov 12, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

AngReader::readFile() uses one column count for a square-grid .ang file. Before, the reader used three different values: it sized the data arrays from NCOLS_ODD (or from NCOLS_EVEN when NCOLS_ODD was not positive), it reordered the data to raster order with NCOLS_ODD, and getXDimension() returned NCOLS_EVEN. 2 files changed, +99 / −0 lines.

  • A square-grid file without a # NCOLS_ODD: line kept the default value -1. The raster reorder converted it to a very large column count and read past the end of the arrays (crash).
  • A file with NCOLS_ODD and NCOLS_EVEN both positive but different returned success, and getXDimension() did not match the number of points that were read. A caller that sizes its output from getXDimension() gets wrong data or reads past the arrays.

For a square grid, readFile() now resolves the column count before it reads the data:

  • If NCOLS_ODD and NCOLS_EVEN are both positive and different, the read fails with error -120.
  • Otherwise it uses NCOLS_ODD if it is positive, and NCOLS_EVEN if not. If neither is positive, the read fails with error -130.
  • It stores the resolved value in both NCOLS_ODD and NCOLS_EVEN, so the allocation, the raster reorder and getXDimension() agree.

Each error message names the file and both values. Hex-grid files, readHeaderOnly() and the HDF5 readers do not change.

This defect was found while reviewing BlueQuartzSoftware/simplnx#1967, which validates the ANG grid dimensions that simplnx uses.

Test plan

  • New tests in Source/Test/AngImportTest.cpp (SquareGridColumnsEvenOnly, SquareGridColumnsOddOnly, SquareGridColumnsMismatch, SquareGridColumnsNonpositive, SquareGridColumnsEqual) write small .ang files and check the number of points, the X dimension, both column counts, the Phi1 values in written order, and the error codes and messages.
  • Before the fix, 4 of the 5 new tests fail: EvenOnly crashes (SIGSEGV), OddOnly gives X dimension -1, Mismatch returns 0, and Nonpositive returns the raster error -101105. The equal-columns control passes.
  • macOS Release (EbsdLib-Release preset): full test suite passes, 434/434.
  • CI passes on all platforms.

Related Issue

  • This PR has no related issue

AngReader::readFile() sized the data arrays from NCOLS_ODD (or NCOLS_EVEN
when NCOLS_ODD was not positive), reordered the data with NCOLS_ODD, and
reported NCOLS_EVEN as the X dimension. A square-grid file without a
NCOLS_ODD line crashed in the raster reorder, and a file with different
NCOLS_ODD and NCOLS_EVEN values returned success with an X dimension that
did not match the data.

For a square grid, readFile() now resolves one column count before it
reads the data and stores it in both values. Different positive values
give error -120, and no positive value gives error -130.

Signed-off-by: Michael Jackson <mike.jackson@bluequartz.net>
@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/ang_square_grid_columns 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