Skip to content

BUG: Reject non-positive Lambert projection and pole figure dimensions - #79

Closed
imikejackson wants to merge 1 commit into
BlueQuartzSoftware:developfrom
imikejackson:fix/lambert-projection-dimension-checks
Closed

imikejackson wants to merge 1 commit into
BlueQuartzSoftware:developfrom
imikejackson:fix/lambert-projection-dimension-checks

Conversation

@imikejackson

Copy link
Copy Markdown
Collaborator

Summary

ModifiedLambertProjection did not check its dimension.

  • initializeSquares(0, r) set m_StepSize = squareEdge / 0 (infinite) and allocated empty squares. LambertBallToSquare() then computed NaN bins and wrote outside the squares: segfault.
  • initializeSquares(-1, r) kept dimension -1 and a negative step size, and converted -1 to size_t for the square size (SIZE_MAX x SIZE_MAX wraps to 1 bin). Other negative values ask for huge allocations.
  • createStereographicProjection(-1) / createCircularProjection(-1) returned a 1-pixel image for the same reason.
  • Pole figure entry points: ComputeStereographicProjection (used by every LaueOps::generatePoleFigure()) wrote into an empty intensity image for imageDim == 0 in discrete mode (segfault). For imageDim == 1, halfDim - 1 is -1, so equator points were written one pixel before or after the 1-pixel image. With lambertDim == 0 the continuous path crashed in the Lambert projection. InversePoleFigureUtilities::computeIPFIntensity() iterated lambertDim * lambertDim bins regardless of what was allocated.
  • The xpoints / 2 and 2.0f / xpoints expressions in the stereographic projection are harmless on their own: when xpoints is 0 the pixel loops do not run.

Design

The class has no error channel (initializeSquares() returns void, LambertBallToSquare() returns a pointer that no caller null-checks). The least invasive fix that keeps every public signature:

  • initializeSquares() rejects a dimension of 0 or less by leaving the projection empty: getDimension() and getStepSize() are 0 and both squares are non-null arrays with 0 bins. This is documented on initializeSquares() and LambertBallToSquare(); callers detect it with getDimension() > 0.
  • addInterpolatedValues() does nothing and getInterpolatedValue() returns 0 on an empty projection, so LambertBallToSquare() and both stereographic projections return all-0 images instead of crashing. Returning NullPointer() from LambertBallToSquare() was rejected because eight existing call sites dereference the result without a check.
  • createStereographicProjection(int) and createCircularProjection() clamp a negative image dimension to 0.
  • ComputeStereographicProjection returns an empty image for imageDim <= 0, and the discrete path skips points outside the image. For imageDim >= 2 every point lands inside, so valid output is unchanged.
  • computeIPFIntensity() counts the bins the projection allocated.
  • No error codes are added; valid dimensions behave as before.

Test Plan

  • New tests in ModifiedLambertProjectionTest.cpp fail on develop and pass with this change:
    • InitializeSquares_NonPositiveDimension: on develop CHECK( mlp->getStepSize() == 0.0f ) fails with inff == 0.0f, then segfaults interpolating.
    • LambertBallToSquare_ZeroDimension: on develop SIGSEGV.
    • CreateProjection_NegativeDimension: on develop stereo->getNumberOfTuples() == 0 fails with 1 == 0 (size_t wrap).
    • ComputeStereographicProjection_SmallDimensions (discrete imageDim 0 and 1, lambertDim 0): on develop SIGSEGV.
    • ComputeIPFIntensity_ZeroLambertDimension: on develop SIGSEGV.
    • No test allocates a large array; -1 is used because its wrap is 1 bin.
  • Linux x64, Release: full ctest suite passes, 434/434.

Related Issue

Related to BlueQuartzSoftware/simplnx#1908 (item L90) and BlueQuartzSoftware/simplnx#1957. simplnx #1965 already range-checks the pole figure dimensions in preflight; this change makes EbsdLib safe for other callers too.

Overlaps: open PR #71 changes the pole-figure compositor (PoleFigureCompositor.cpp), which this PR does not touch; no file overlap and no merge-order requirement.

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

* ModifiedLambertProjection::initializeSquares() divided the square edge
  by the dimension (infinite step size for 0) and converted a negative
  dimension to size_t (wrapped). Binning or interpolating into such a
  projection read and wrote outside the squares and crashed.
* initializeSquares() now leaves the projection empty for a dimension of
  0 or less: getDimension() and getStepSize() are 0 and the squares hold
  no bins. addInterpolatedValues() does nothing and
  getInterpolatedValue() returns 0 on an empty projection, so
  LambertBallToSquare() and the stereographic projections produce all-0
  images instead of crashing. Valid dimensions are unchanged.
* createStereographicProjection(int) and createCircularProjection() no
  longer wrap a negative image dimension into a non-empty image.
* ComputeStereographicProjection returns an empty image for an image
  dimension of 0 or less, and the discrete path skips points that fall
  outside the image (an image dimension of 1 wrote one pixel before or
  after the image).
* InversePoleFigureUtilities::computeIPFIntensity() counts the bins the
  projection allocated instead of lambertDim * lambertDim.

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/lambert-projection-dimension-checks branch November 13, 2026 16:28
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