Skip to content

BUG: Handle narrow bands with fewer nodes than work units (supersedes #6992) - #7013

Open
hjmjohnson wants to merge 2 commits into
InsightSoftwareConsortium:mainfrom
hjmjohnson:narrowband-small-band-takeover
Open

hjmjohnson wants to merge 2 commits into
InsightSoftwareConsortium:mainfrom
hjmjohnson:narrowband-small-band-takeover

Conversation

@hjmjohnson

Copy link
Copy Markdown
Member

Supersedes #6992 by @jdotc1, keeping that fix and its authorship. Narrow-band filters no longer read past the per-work-unit region list when the band has fewer nodes than work units, and stop iterating once the band is empty. Closes #6823.

Behavior change for maintainers to accept: when the band becomes empty, NarrowBandImageFilterBase::GenerateData stops: GetElapsedIterations() stays at the last count, and no IterationEvent is sent for that pass. At main the same input read an empty vector out of bounds, so no working behavior is lost.

Changes relative to #6992
  • Squashed the two STYLE commits into the BUG commit; Jeff remains its author.
  • Rewrote the BUG commit message with the what and why, including the SplitBand return-size change and the empty-band stop.
  • Converted itkNarrowBandSmallBandTest to GoogleTest (itkNarrowBandSmallBandGTest), adding ITKGoogleTest to the module's TEST_DEPENDS.
  • Named the image size, initial value, band row, first band column, and iteration limit; replaced the nested ternary with ExpectedElapsedIterations(); renamed Configure(count, shrink) to SetBand(numberOfNodes, emptyBandAfterFirstIteration) and RequestSplitRegion to GetSplitRegionOfWorkUnit.
  • New commit: an IsoContourDistanceImageFilter test with a one-node band over eight work units. That filter also indexes SplitBand's result by work-unit id and was fixed silently by the padding.
Local verification

macOS arm64, AppleClang, RelWithDebInfo with AddressSanitizer; modules NarrowBand and DistanceMap plus their IO.

Test main headers this PR
NarrowBand.SplitBandReturnsOneContiguousRegionPerWorkUnit fails: region count pass
NarrowBandImageFilterBase.UpdatesBandWithFewerNodesThanWorkUnits ASan SEGV pass
IsoContourDistanceImageFilter.NarrowBandWithFewerNodesThanWorkUnits ASan heap-buffer-overflow on a worker thread pass

All 34 NarrowBand and DistanceMap tests pass at the tip, and pre-commit run --all-files passes.

AI assistance

Claude Code performed the review of #6992, the GoogleTest conversion, the IsoContour test, and the AddressSanitizer runs; I reviewed and directed each change.

jdotc1 and others added 2 commits October 25, 2026 10:04
NarrowBand::SplitBand returned at most one region per band node, while
NarrowBandImageFilterBase and IsoContourDistanceImageFilter index the
result by work-unit id. A band with fewer nodes than work units was
read past its end, and an empty band divided zero by zero.

SplitBand now returns exactly one region per work unit, padding with
empty ranges. Empty work units are left out of the time-step choice,
because an empty range reports a zero time step that would freeze the
whole band. GenerateData stops when the band becomes empty, since no
work unit then has a valid time step to resolve.

Closes InsightSoftwareConsortium#6823.
A one-node narrow band split across eight work units exercises the
padded regions that SplitBand now returns for unused work units.
@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:Filtering Issues affecting the Filtering module area:Numerics Issues affecting the Numerics module labels Oct 25, 2026
@hjmjohnson

Copy link
Copy Markdown
Member Author

@jdotc1 Some improvements on your proposed PR. Feel free to review this, or update your PR.

@hjmjohnson
hjmjohnson marked this pull request as ready for review October 26, 2026 00:05
@greptile-apps

greptile-apps Bot commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; no actionable issues were found.

Summary

Fixes narrow bands with fewer nodes than work units.

  • Every worker gets a region when a narrow band is smaller than the worker count.
  • Narrow-band filters skip empty worker ranges and stop when no nodes remain.

No actionable issues found. Tests were not run during this review.

Acknowledged by hjmjohnson:

  • An empty-band pass intentionally leaves GetElapsedIterations() unchanged and sends no IterationEvent.
  • Raising the work-unit count with ManualReinitialization can still overrun m_TouchedForThread; this predates the PR and is deferred.

Reviews (1) · Last reviewed commit: "ENH: Test IsoContourDistanceImageFilter ..." · Reviewed by Greptile

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 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.

NarrowBandImageFilterBase reads m_RegionList out of bounds when the band has fewer nodes than work units

2 participants