Skip to content

UBSan finds invalid cast in itkPeriodicBoundaryCondition.hxx #2353

@seanm

Description

@seanm

Building current itk master using clang UBSan (undefined behaviour sanitizer) I get this error from the itkPeriodicBoundaryConditionTest test:

/ITK/Modules/Core/Common/include/itkPeriodicBoundaryCondition.hxx:60:17: runtime error: member call on address 0x00016d7da420 which does not point to an object of type 'itk::ConstNeighborhoodIterator<itk::Image<int, 2>, itk::PeriodicBoundaryCondition<itk::Image<int, 2>, itk::Image<int, 2>>>'

It's from this code:

namespace itk
{
template <typename TInputImage, typename TOutputImage>
typename PeriodicBoundaryCondition<TInputImage, TOutputImage>::OutputPixelType
PeriodicBoundaryCondition<TInputImage, TOutputImage>::operator()(const OffsetType &       point_index,
                                                                 const OffsetType &       boundary_offset,
                                                                 const NeighborhoodType * data) const
{
  // This is guaranteed to be called with an object that is using
  // PeriodicBoundaryCondition
  const auto * iterator = reinterpret_cast<const ConstNeighborhoodIterator<TInputImage, Self> *>(data);

If you change that to dynamic_cast and assert the result, you'll see it's null. (That's a way to repro/debug without UBSan).

Alas, I don't know this code enough to debug further...

Metadata

Metadata

Assignees

Labels

status:Use_Milestone_BacklogUse "Backlog" milestone instead of label for issues without a fixed deadlinetype:BugInconsistencies or issues which will cause an incorrect result under some or all circumstances

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions