Skip to content

BUG: Validate TileImageFilter Layout has no zero before the last axis#6630

Merged
hjmjohnson merged 1 commit into
InsightSoftwareConsortium:mainfrom
physwkim:bug-tile-image-filter-layout-6575
Jul 14, 2026
Merged

BUG: Validate TileImageFilter Layout has no zero before the last axis#6630
hjmjohnson merged 1 commit into
InsightSoftwareConsortium:mainfrom
physwkim:bug-tile-image-filter-layout-6575

Conversation

@physwkim

Copy link
Copy Markdown
Contributor

TileImageFilter never validates Layout: a 0 in any axis but the last indexes an empty std::vector and runs a loop of about 2^32 iterations, and the constructor's own all-zero default divides by zero. Addresses B87 of #6575.

Root cause and fix

Only the last axis of Layout may be 0 (meaning "as many tiles as needed"); a 0 anywhere else is meaningless, and the tile-index arithmetic in GenerateData() has no defense against it. Rather than guarding each use site, VerifyPreconditions() now rejects a zero in any non-last axis, so GenerateData() cannot be reached with an unusable layout.

Local validation

Two cases added to itkTileImageFilterGTest.cxx:

  • RejectsZeroInNonLastLayoutAxis — fail-before: no exception (then UB). Pass-after: throws.
  • RejectsDefaultZeroLayout — same, for the constructor default.

ctest -L ImageGrid: 69/69 pass, unchanged.

AI assistance

A zero in any non-last Layout entry makes
GenerateOutputInformation divide by zero or index an empty
vector. Reject it in VerifyPreconditions before the output
region is computed.

Addresses item B87 of InsightSoftwareConsortium#6575.
@github-actions github-actions Bot added type:Bug Inconsistencies or issues which will cause an incorrect result under some or all circumstances type:Testing Ensure that the purpose of a class is met/the results on a wide set of test cases are correct area:Filtering Issues affecting the Filtering module labels Jul 14, 2026
@greptile-apps

greptile-apps Bot commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR adds layout validation to TileImageFilter. The main changes are:

  • Adds a VerifyPreconditions() override for the filter.
  • Rejects zero layout entries before the last output axis.
  • Adds tests for explicit non-last zero layout and default zero layout.

Confidence Score: 5/5

This looks safe to merge.

No blocking issues found in the changed code.

No files need attention.

T-Rex T-Rex Logs

What T-Rex did

  • The tool-detection pass confirmed CMake and CTest are unavailable while g++ and make are available.
  • The narrow CMake configure attempt and the cmake-not-found blocker were reviewed from the CMake configure log.
  • The PR test file was verified to include RejectsZeroInNonLastLayoutAxis and RejectsDefaultZeroLayout as shown in the test-presence log.
  • Before/after runtime evidence was captured from the compiled C++ harnesses.

View all artifacts

T-Rex Ran code and verified through T-Rex

Important Files Changed

Filename Overview
Modules/Filtering/ImageGrid/include/itkTileImageFilter.h Declares the new precondition hook for layout validation.
Modules/Filtering/ImageGrid/include/itkTileImageFilter.hxx Rejects zero layout entries in non-last dimensions before output generation.
Modules/Filtering/ImageGrid/test/itkTileImageFilterGTest.cxx Adds tests for invalid zero-layout configurations.

Reviews (2): Last reviewed commit: "BUG: Validate Layout has no zero before ..." | Re-trigger Greptile

@blowekamp
blowekamp self-requested a review July 14, 2026 14:25
@hjmjohnson
hjmjohnson marked this pull request as draft July 14, 2026 14:58
@hjmjohnson
hjmjohnson marked this pull request as ready for review July 14, 2026 15:01
@hjmjohnson
hjmjohnson merged commit ab57477 into InsightSoftwareConsortium:main Jul 14, 2026
20 of 22 checks passed
hjmjohnson added a commit to hjmjohnson/ITK that referenced this pull request Jul 15, 2026
The product of the non-last-axis Layout counts was accumulated in a
32-bit int before being used as a division-by-zero-prone divisor to
auto-size the last axis. For a large Layout (e.g. {65536, 65536, 0}),
the product wraps in 32-bit arithmetic and can land on exactly 0,
turning the division into a SIGFPE on architectures whose idiv traps.

Widen the accumulator to SizeValueType and reject the pathological
case where it's still zero.

Forward-fix for the review finding on PR InsightSoftwareConsortium#6630 (merged).
hjmjohnson added a commit to hjmjohnson/ITK that referenced this pull request Jul 15, 2026
The product of the non-last-axis Layout counts was accumulated in a
32-bit int before being used as a division-by-zero-prone divisor to
auto-size the last axis. For a large Layout (e.g. {65536, 65536, 0}),
the product wraps in 32-bit arithmetic and can land on exactly 0,
turning the division into a SIGFPE on architectures whose idiv traps.

Widen the accumulator to SizeValueType and reject the pathological
case where it's still zero.

Forward-fix for the review finding on PR InsightSoftwareConsortium#6630 (merged).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:Filtering Issues affecting the Filtering module type:Bug Inconsistencies or issues which will cause an incorrect result under some or all circumstances 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