Skip to content

Commit

Permalink
Out of bounds check
Browse files Browse the repository at this point in the history
Out of bounds check for meshes.

Signed-off-by: ghurstunither <[email protected]>
  • Loading branch information
ghurstunither committed Oct 11, 2024
1 parent 10fecd4 commit 7c753e5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
5 changes: 5 additions & 0 deletions openvdb/openvdb/tools/LevelSetThickenedMesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -1008,6 +1008,8 @@ class TriangleMeshEdgeConnectivity {
TriangleMeshEdgeConnectivity(const std::vector<Vec3s>& coords, const std::vector<Vec3I>& cells)
: mCoords(coords), mCells(cells)
{
const Index n = coords.size();

mNormals.resize(cells.size());

for (Index i = 0; i < cells.size(); i++) {
Expand All @@ -1023,6 +1025,9 @@ class TriangleMeshEdgeConnectivity {
mEdgeMap[edge].push_back(i);
}

if (cell[0] >= n || cell[1] >= n || cell[2] >= n)
OPENVDB_THROW(ValueError, "out of bounds index");

const Vec3s &p1 = mCoords[cell[0]],
&p2 = mCoords[cell[1]],
&p3 = mCoords[cell[2]];
Expand Down
6 changes: 6 additions & 0 deletions openvdb/openvdb/tools/LevelSetTubes.h
Original file line number Diff line number Diff line change
Expand Up @@ -1276,12 +1276,18 @@ class TubeComplexVoxelizer {
inline void
computeCentroids(std::vector<Vec3s>& centroids)
{
const Index n = mCoords.size();

centroids.resize(mCells.size());

tbb::parallel_for(tbb::blocked_range<size_t>(0, centroids.size()),
[&](const tbb::blocked_range<size_t>& r) {
for (size_t i = r.begin(); i != r.end(); ++i) {
const Vec2I &cell = mCells[i];

if (cell[0] >= n || cell[1] >= n)
OPENVDB_THROW(ValueError, "out of bounds index");

centroids[i] = 0.5f * (mCoords[cell[0]] + mCoords[cell[1]]);
}
});
Expand Down

0 comments on commit 7c753e5

Please sign in to comment.