Skip to content

BUG: Report an error when an ANG header number cannot be parsed - #82

Closed
imikejackson wants to merge 1 commit into
BlueQuartzSoftware:developfrom
imikejackson:fix/ang-header-parse-failure
Closed

imikejackson wants to merge 1 commit into
BlueQuartzSoftware:developfrom
imikejackson:fix/ang-header-parse-failure

Conversation

@imikejackson

@imikejackson imikejackson commented Nov 13, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

AngHeaderEntry::parseValue() read a numeric header value with ss >> m_value and did not check the stream. A value that is not a number or is out of range was accepted with no error:

Header line Value stored on develop
# XSTEP: 1e999 3.40282e+38 (FLT_MAX)
# YSTEP: abc 0
# NROWS: 99999999999 2147483647 (INT_MAX)
# NCOLS_ODD: two 0

readHeaderOnly() returned success for all of these, so a caller such as the simplnx ReadAngDataFilter preflight used the value as Image Geometry spacing or dimensions. readFile() then failed later with an unrelated error (-110 zero step, -101105 grid mismatch), or threw std::bad_alloc for the NROWS overflow.

  • A numeric header entry now records a failed parse, and for float entries also a non-finite value. The new virtual EbsdHeaderEntry::hasParseError() returns false by default, so text entries and the CTF entries do not change (additive API).
  • AngReader::parseHeaderLine() reports the first such value as an error. readFile() already stops after the header when the error code is negative.
  • readHeaderOnly() now clears the previous error at the start, as readFile() does, and returns the error code when the header has one. For a valid header it still returns 1.
Code Failure
-115 A numeric header value cannot be parsed or is not finite. The message names the file, the header key and the raw text, for example Ang file '<path>' has a header value that is not a valid number: XSTEP = '1e999'. Correct the value in the header.

Not changed:

  • An empty numeric value (# XSTEP:) never reaches parseValue(); the entry keeps its default and the existing checks reject it (-110 for a step, -200 for NROWS).
  • Trailing text after a number (12abc) is still read as the number. Rejecting it was not needed for this defect.
  • Negative XSTEP/YSTEP: I checked this (simplnx#1908 item L88). readFile() on develop already rejects a negative step for a square grid (-101104 from the raster-order check, also for a 1 x 1 grid), and hex grids are rejected with -400, so no change was made. Non-positive NCOLS is handled by BUG: Use one column count for a square-grid ANG file #73; NROWS < 1 is already -200.

Test Plan

  • New test EbsdLib::ebsdlib::AngImportTest-TestUnparsableHeaderValue (in AngImportTest.cpp) fails on develop and passes with this change. It writes small .ang files with XSTEP: 1e999, YSTEP: abc, NROWS: 99999999999 and NCOLS_ODD: two, checks readHeaderOnly() and readFile() both return -115 with the file, key and raw text in the message, and checks that a valid header still reads. On develop: readHeaderOnly() returned 1 for every case; readFile() returned -101105, -110 or threw std::bad_alloc.
  • Linux x64, Release: full ctest suite passes, 430/430.

Overlap

#73 (fix/ang_square_grid_columns) also changes AngReader.cpp (the square-grid column check in readFile(), codes -120 and -130). The hunks do not overlap; either merge order works.

Related Issue

Related to BlueQuartzSoftware/simplnx#1877 (item ReadAngDataFilter.cpp:119, XSTEP/YSTEP reach Image Geometry spacing unchecked) and BlueQuartzSoftware/simplnx#1908 (item L88).

🤖 Generated with Claude Code

- AngHeaderEntry::parseValue() ignored a failed stream read. A header such
  as "XSTEP: 1e999" (overflow), "YSTEP: abc" or "NROWS: 99999999999" was
  accepted with FLT_MAX, 0 or INT_MAX. readHeaderOnly() returned success,
  so callers used the bad value (for example as geometry spacing), and
  readFile() then failed with an unrelated error or threw std::bad_alloc.
- A numeric header entry now records a failed or non-finite parse
  (EbsdHeaderEntry::hasParseError(), default false). AngReader reports it
  as error -115 with a message that names the file, the header key and the
  raw text. readHeaderOnly() now clears the previous error and returns the
  error code when the header has one.
- Valid headers are read exactly as before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@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-header-parse-failure 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