Repository navigation
BUG: Reject non-positive Lambert projection and pole figure dimensions - #79
Closed
imikejackson wants to merge 1 commit into
Closed
imikejackson wants to merge 1 commit into
imikejackson wants to merge 1 commit into
Conversation
* 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>
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
ModifiedLambertProjectiondid not check its dimension.initializeSquares(0, r)setm_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 tosize_tfor 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.ComputeStereographicProjection(used by everyLaueOps::generatePoleFigure()) wrote into an empty intensity image forimageDim == 0in discrete mode (segfault). ForimageDim == 1,halfDim - 1is -1, so equator points were written one pixel before or after the 1-pixel image. WithlambertDim == 0the continuous path crashed in the Lambert projection.InversePoleFigureUtilities::computeIPFIntensity()iteratedlambertDim * lambertDimbins regardless of what was allocated.xpoints / 2and2.0f / xpointsexpressions in the stereographic projection are harmless on their own: whenxpointsis 0 the pixel loops do not run.Design
The class has no error channel (
initializeSquares()returnsvoid,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()andgetStepSize()are 0 and both squares are non-null arrays with 0 bins. This is documented oninitializeSquares()andLambertBallToSquare(); callers detect it withgetDimension() > 0.addInterpolatedValues()does nothing andgetInterpolatedValue()returns 0 on an empty projection, soLambertBallToSquare()and both stereographic projections return all-0 images instead of crashing. ReturningNullPointer()fromLambertBallToSquare()was rejected because eight existing call sites dereference the result without a check.createStereographicProjection(int)andcreateCircularProjection()clamp a negative image dimension to 0.ComputeStereographicProjectionreturns an empty image forimageDim <= 0, and the discrete path skips points outside the image. ForimageDim >= 2every point lands inside, so valid output is unchanged.computeIPFIntensity()counts the bins the projection allocated.Test Plan
ModifiedLambertProjectionTest.cppfail ondevelopand pass with this change:InitializeSquares_NonPositiveDimension: on developCHECK( mlp->getStepSize() == 0.0f )fails withinff == 0.0f, then segfaults interpolating.LambertBallToSquare_ZeroDimension: on develop SIGSEGV.CreateProjection_NegativeDimension: on developstereo->getNumberOfTuples() == 0fails with1 == 0(size_t wrap).ComputeStereographicProjection_SmallDimensions(discrete imageDim 0 and 1, lambertDim 0): on develop SIGSEGV.ComputeIPFIntensity_ZeroLambertDimension: on develop SIGSEGV.ctestsuite 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-skillsskills (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