Skip to content

BUG: Report an error for a short ANG LatticeConstants or hklFamilies line - #85

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

imikejackson wants to merge 1 commit into
BlueQuartzSoftware:developfrom
imikejackson:fix/ang-lattice-constants-count

Conversation

@imikejackson

Copy link
Copy Markdown
Collaborator

Summary

Two phase-line parsers in AngPhase.cpp indexed the token vector without checking its size:

  • parseLatticeConstants() read tokens[1] to tokens[6]. A short line such as # LatticeConstants 3.52 3.52 read past the end of the vector. On develop (Linux, Release) std::stof then threw std::invalid_argument("stof") out of readHeaderOnly() and readFile(); the result of the out-of-bounds read is undefined, so other builds can crash or read garbage. A value that is not a number (# LatticeConstants 3.52 3.52 abc 90 90 90) threw the same uncaught exception.
  • parseHKLFamilies() read tokens[1] to tokens[5]. A short line such as # hklFamilies 2 0 read past the end of the vector and added a family, with no error.

Changes:

  • parseLatticeConstants() returns with no lattice constants for a line with fewer than 6 values, and catches the std::stof exceptions (as parseHKLFamilies() already does) and clears the values.
  • parseHKLFamilies() adds no family for a line with fewer than 5 values. An unparsable value in a full-length line is still handled as before.
  • AngReader::parseHeaderLine() reports the first such line 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.
  • parseCategories() already uses at() and loops over the token count; parseMaterialName() and parseFormula() loop over the tokens. They are not changed. No public signatures change.
Code Failure
-117 A LatticeConstants line does not hold 6 numbers. The message names the file, the phase index and the line.
-118 An hklFamilies line does not hold h, k, l, s1 and the diffraction intensity. The message names the file, the phase index and the line.

All local .ang files I checked (test data and others on this machine) have 6 lattice constants and 5 or 6 hklFamilies values, so valid files are not affected.

Test Plan

  • New test EbsdLib::ebsdlib::AngImportTest-TestShortPhaseLines (in AngImportTest.cpp) fails on develop and passes with this change. It writes small .ang files with a short LatticeConstants line, a non-numeric lattice constant and a short hklFamilies line, checks that readHeaderOnly() and readFile() return -117/-118 with the file and the line in the message, and checks that valid phase lines still read. On develop: the two LatticeConstants cases failed with unexpected exception with message: stof; the short hklFamilies case returned 1 / 0 (accepted, 2 families).
  • Linux x64, Release: full ctest suite passes, 430/430.

Overlap

Related Issue

Not filed separately. It is in the same class as BlueQuartzSoftware/simplnx#1877 (hand-written readers that index tokens without a size check), found while working on #82.

🤖 Generated with Claude Code

…line

- AngPhase::parseLatticeConstants() read tokens[1..6] without checking the
  token count. A short line such as "LatticeConstants 3.52 3.52" read past
  the end of the vector, and std::stof then threw std::invalid_argument out
  of readHeaderOnly() and readFile(). A value that is not a number threw
  the same exception.
- AngPhase::parseHKLFamilies() read tokens[1..5] without checking the
  token count. A short line read past the end of the vector and added a
  family with no error.
- A short or unparsable LatticeConstants line now leaves the lattice
  constants empty, and a short hklFamilies line adds no family. AngReader
  reports these as -117 and -118 with a message that names the file, the
  phase and the line. readHeaderOnly() now clears the previous error and
  returns the error code when the header has one.
- parseCategories() already uses at() and the token count, so it is not
  changed. Valid headers are read exactly as before.

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/ang-lattice-constants-count 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