InsightSoftwareConsortium / InsightSoftwareConsortium/ITK

`PointSet::SetPoints(PointsVectorContainer *)` overload leads to undefined behavior

Open
#4,848 3 comments 0 reactions 1 assignee Claimed by @N-Dekker View on GitHub
type:Bug
Dominant language
C++
Stars
1.7k
Forks
748
Avg merge
1d 1h
Merged PRs (30d)
64

Description

### Description

`PointSet::SetPoints(PointsVectorContainer * points)` internally casts its argument to a `PointsContainer *`:

https://github.com/InsightSoftwareConsortium/ITK/blob/9a5dade7f7e13fcef307f8224a01c2ce2b0ab13b/Modules/Core/Common/include/itkPointSet.hxx#L76

This leads to undefined behavior, when the `PointsVectorContainer` object is being used as a `PointsContainer` object.

### Steps to Reproduce

The test code already has undefined behavior, even if it might just work on the currently tested platforms:

https://github.com/InsightSoftwareConsortium/ITK/blob/9a5dade7f7e13fcef307f8224a01c2ce2b0ab13b/Modules/Core/Common/test/itkPointSetTest.cxx#L102-L127

### Versions

- The `PointSet::SetPoints(PointsVectorContainer *)` overload is introduced by pull request #3154 commit 6827360fa6a06fbe073911d7f8554c2c3368721d "ENH: Adding SetPoints in PointSet for 1D input array", merged on Mar 16, 2022, and included with both [v5.3.0](https://github.com/InsightSoftwareConsortium/ITK/releases/tag/v5.3.0) and [v5.4.0](https://github.com/InsightSoftwareConsortium/ITK/releases/tag/v5.4.0).

### Additional Information

Discussed before at https://github.com/InsightSoftwareConsortium/ITK/pull/3154#discussion_r1755213148, with @PranjalSahu

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.