Repository navigation
BUG: Report an error for a short ANG LatticeConstants or hklFamilies line - #85
Closed
imikejackson wants to merge 1 commit into
Closed
imikejackson wants to merge 1 commit into
imikejackson wants to merge 1 commit into
Conversation
…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>
7 tasks done
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Two phase-line parsers in
AngPhase.cppindexed the token vector without checking its size:parseLatticeConstants()readtokens[1]totokens[6]. A short line such as# LatticeConstants 3.52 3.52read past the end of the vector. Ondevelop(Linux, Release)std::stofthen threwstd::invalid_argument("stof")out ofreadHeaderOnly()andreadFile(); 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()readtokens[1]totokens[5]. A short line such as# hklFamilies 2 0read 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 thestd::stofexceptions (asparseHKLFamilies()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, asreadFile()does, and returns the error code when the header has one. For a valid header it still returns 1.parseCategories()already usesat()and loops over the token count;parseMaterialName()andparseFormula()loop over the tokens. They are not changed. No public signatures change.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
EbsdLib::ebsdlib::AngImportTest-TestShortPhaseLines(inAngImportTest.cpp) fails ondevelopand 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 thatreadHeaderOnly()andreadFile()return -117/-118 with the file and the line in the message, and checks that valid phase lines still read. Ondevelop: the two LatticeConstants cases failed withunexpected exception with message: stof; the short hklFamilies case returned 1 / 0 (accepted, 2 families).ctestsuite passes, 430/430.Overlap
fix/ang-header-parse-failure) makes the same change toAngReader::readHeaderOnly()(clear the error at the start, return it at the end) and adds error -115 inparseHeaderLine(). Whichever merges second may need a trivial conflict resolution inreadHeaderOnly(); keep one copy of the change.fix/ang_square_grid_columns) also changesAngReader.cpp(readFile(), codes -120 and -130). The hunks do not 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