Repository navigation
BUG: Reject invalid grid header values in the CTF and CPR readers - #76
Closed
imikejackson wants to merge 1 commit into
Closed
imikejackson wants to merge 1 commit into
imikejackson wants to merge 1 commit into
Conversation
- Before: CtfReader::readFile() and CprReader::readFile() only rejected a step or cell count of exactly zero. Negative, NaN and infinite steps were accepted (a 3D .ctf file skips the raster-order check that otherwise catches them), negative .cpr xCells/yCells were accepted (-1 x -1 read as a 1 point grid), and a .ctf "ZCells 0" header allocated zero-length arrays that the raster order check then read past. - After: non-finite or negative steps and non-positive ZCells (.ctf) or negative xCells/yCells (.cpr) return new negative error codes (-102310..-102312 for .ctf, -102320..-102323 for .cpr) with a message that names the file, the header key and the value. Zero values keep their existing codes (-102, -103) and a .ctf file without a ZCells line is still read as one slice. - Add HklGridHeaderValidationTest with small synthetic .ctf and .cpr files. 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, FULL_COUNT.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