Skip to content

BUG: Reject transform parameter counts that exceed the metric limit (5.4) - #7215

Open
gdevenyi wants to merge 1 commit into
InsightSoftwareConsortium:release-5.4from
gdevenyi:backport-6991-metric-count-guard-5.4
Open

gdevenyi wants to merge 1 commit into
InsightSoftwareConsortium:release-5.4from
gdevenyi:backport-6991-metric-count-guard-5.4

Conversation

@gdevenyi

Copy link
Copy Markdown
Contributor

Backport of #6991 to release-5.4. A metric with more than 2^32 − 1 transform parameters now throws instead of truncating the count and writing past the derivative buffer. SyN hits this above about 1.43 billion voxels in 3-D (#6949).

Backport notes
Testing

On release-5.4 (6e154ce644), GCC 15, a minimal registration build with Module_ITKGoogleTest and Module_ITKOptimizersv4 on:

  • ObjectToObjectMetric.PreservesRepresentableParameterCounts and .RejectsParameterCountOverflow pass.
  • With the guard reverted, RejectsParameterCountOverflow fails.
  • ctest -L ITKOptimizersv4: 31/32 pass. The one not run is ITKOptimizersv4KWStyleTest, because KWStyle is not installed locally.
AI assistance
  • Tool: Claude Code (claude-opus-5-5)
  • Role: cherry-picked the commit, resolved the CMake conflict, and ran the local build and tests
  • All code was reviewed and tested locally before committing

@github-actions github-actions Bot added type:Bug Inconsistencies or issues which will cause an incorrect result under some or all circumstances type:Infrastructure Infrastructure/ecosystem related changes, such as CMake or buildbots type:Testing Ensure that the purpose of a class is met/the results on a wide set of test cases are correct area:Numerics Issues affecting the Numerics module labels Nov 19, 2026

@hjmjohnson hjmjohnson left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Max review (Standards and Spec): no should-fix findings. The guard and test match the main commit from #6991; the change is limited to counts that previously truncated, with no API or ABI change, which fits a patch release. One optional placement nit below.

Optional nits
  • The backport note in the commit message has one 73-column line.
  • itkObjectToObjectMetric.hxx:133,136 computes the same maximum twice; that would change on main first, so leave it here.

@hjmjohnson

Copy link
Copy Markdown
Member

@greptileai review

@greptile-apps

greptile-apps Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

security Security Review

This PR appears safe to merge from a security standpoint.

What was checked
  • The new guard compares the transform's 64-bit parameter count against the metric's 32-bit limit in the wider type, so the check is correct on 64-bit-ID platforms and a harmless no-op where both types are 32 bits.
  • Every derivative and gradient buffer sizing I traced in the Metricsv4 and Optimizersv4 modules goes through the now-guarded virtual GetNumberOfParameters(), and no subclass overrides it, so the overflow path is fully blocked instead of just moved.
  • The guard throws via itkExceptionMacro, so an oversized transform count now aborts the registration instead of truncating and letting the metric write past the derivative buffer.
  • The new GoogleTest driver, test file, and ITKGoogleTest test dependency only affect the test build, not the shipped library.

@greptile-apps

greptile-apps Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Confidence Score: 5/5 · The PR appears safe to merge; no blocking issues remain.RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; no blocking issues remain.

Summary

The PR rejects transform parameter counts that exceed the metric’s limit before converting them to the smaller count type.

  • Object-to-object metrics reject transform counts they cannot represent.

Review was based on source inspection; no builds or tests were run.

Reviews (3) · Last reviewed commit: "BUG: Reject transform parameter counts t..." · Reviewed by Greptile

ObjectToObjectMetric::GetNumberOfParameters returned the moving
transform's 64-bit IdentifierType count through the metric's unsigned
int NumberOfParametersType, so a dense displacement field with more
than 2^32 - 1 parameters was silently truncated. Callers then sized the
derivative from the truncated count and wrote past its end.

Throw instead when the count does not fit. This makes the overflow a
clear error; widening the metric API remains open.

Addresses InsightSoftwareConsortium#6949.

(cherry picked from commit cc15831)

release-5.4 had no GoogleTest driver for ITKOptimizersv4, so the
backport adds one for itkObjectToObjectMetricGTest.cxx and adds
ITKGoogleTest to the module's TEST_DEPENDS.
@gdevenyi
gdevenyi force-pushed the backport-6991-metric-count-guard-5.4 branch from 96d6e57 to f0a7a01 Compare November 26, 2026 03:35
@gdevenyi

Copy link
Copy Markdown
Contributor Author

Force-push 96d6e57531 → f0a7a0197d, no rebase. Changes:

  • ITKGoogleTest added to TEST_DEPENDS (Greptile's P1, reproduced and fixed in a minimal configure);
  • the GoogleTest block moved to the end of test/CMakeLists.txt;
  • the backport note re-wrapped to 72 columns, and it now mentions the TEST_DEPENDS change.

The minimal release-5.4 build's ctest passes 488/488.

@hjmjohnson

Copy link
Copy Markdown
Member

@greptileai review

@gdevenyi
gdevenyi marked this pull request as ready for review November 26, 2026 19:30
Copilot AI balanced review requested due to automatic review settings November 26, 2026 19:30

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:Numerics Issues affecting the Numerics module type:Bug Inconsistencies or issues which will cause an incorrect result under some or all circumstances type:Infrastructure Infrastructure/ecosystem related changes, such as CMake or buildbots type:Testing Ensure that the purpose of a class is met/the results on a wide set of test cases are correct

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants