Skip to content

BUG: Report an error when a .cpr file defines no phases - #75

Closed
imikejackson wants to merge 1 commit into
BlueQuartzSoftware:developfrom
imikejackson:fix/cpr-reader-no-phases
Closed

imikejackson wants to merge 1 commit into
BlueQuartzSoftware:developfrom
imikejackson:fix/cpr-reader-no-phases

Conversation

@imikejackson

Copy link
Copy Markdown
Collaborator

Summary

Callers take a crystal-structure value from a file (where UnknownCrystalStructure is 999) or from a phase's determineOrientationOpsIndex() and index LaueOps::GetAllOrientationOps() with it. A value outside the vector reads out of bounds. EbsdLib had no range-checked accessor: the only static lookups were GetAllOrientationOps() (unchecked vector) and GetLaueOpsFromSpaceGroupNumber() (takes a space-group number, not a crystal structure).

  • New additive API, named after GetLaueOpsFromSpaceGroupNumber() from BUG: Map space groups 1-230 to the correct Laue class #67:
    static LaueOps::Pointer LaueOps::GetOrientationOpsFromCrystalStructure(uint32_t crystalStructure)
  • It returns the same LaueOps subclass as GetAllOrientationOps()[crystalStructure] for each ebsdlib::CrystalStructure constant 0-10, and NullPointer() for LaueGroupEnd (11), UnknownCrystalStructure (999) and every other value.
  • LaueGroupEnd (11) is rejected on purpose. GetAllOrientationOps() has a 12th entry (an OrthoRhombicOps labelled "Axis OrthorhombicOps"), but 11 is the end marker of the Laue groups, not a crystal structure. Callers that want the legacy entry can still index the vector.
  • Performance note (no change here): GetAllOrientationOps() builds a new vector of 12 newly allocated LaueOps objects on every call. The new accessor creates only the requested object.
  • No EbsdLib-internal call site indexes GetAllOrientationOps() with an unchecked value from a file: the readers' printSelf() already use GetLaueOpsFromSpaceGroupNumber() with a null check, and PoleFigureCompositor / DiscretePoleFigureCompositor already compare laueOpsIndex with the vector size. The apps index it with literals. So no call sites change.
  • No error codes are added.

Test Plan

  • New test EbsdLib::ebsdlib::LaueOpsTest::GetOrientationOpsFromCrystalStructure (in LaueOpsTest.cpp). On develop it does not compile ('GetOrientationOpsFromCrystalStructure' is not a member of 'ebsdlib::LaueOps'): there is no checked accessor. With this change it passes. It checks every valid constant against an independent table of class names and against GetAllOrientationOps(), and that 11, 12, 999 and UINT32_MAX return null. (LaueOps has no getCrystalStructure() method, so the test compares class names.)
  • Linux x64, Release: full ctest suite passes, FULL_COUNT.

Related Issue

Related to BlueQuartzSoftware/simplnx#1867 (class C07e), BlueQuartzSoftware/simplnx#1879, and the unchecked index in simplnx WriteGBCDGMTFile.cpp. simplnx can switch those call sites to this accessor once this is merged.

Overlaps: open PRs #60, #61, #64 and #74 also change LaueOps.cpp (and #60/#61 LaueOps.h and LaueOpsTest.cpp). This change only adds a function and a test case, so any conflict is textual; merge order does not matter.

The bluequartz-skills skills (cpp-best-practices, simplnx-best-practices) could not be loaded in this environment; the repository's CLAUDE.md coding standards were followed.

🤖 Generated with Claude Code

- Before: CprReader::readHeaderOnly() did not check the [Phases] Count value.
  When the key was missing, not an integer, or <= 0, the phase loop ran zero
  times and readHeaderOnly()/readFile() returned 0 with an empty phase vector.
- After: a missing, unreadable or non-positive phase count returns -102300 with
  a message that names the .cpr file and the value. Files that define at least
  one phase are read as before.
- Add CprReaderTest, which writes small .cpr/.crc pairs with and without phases.

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

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