Commit a24fd763 authored by Cory Quammen's avatar Cory Quammen Committed by Kitware Robot
Browse files

Merge topic 'intersection-filter-fix-release' into release

77183b27

 Fix out-of-bounds memory write

Acked-by: Kitware Robot's avatarKitware Robot <kwrobot@kitware.com>
Acked-by: default avatarDavid E. DeMarle <dave.demarle@kitware.com>
Acked-by: Sean McBride's avatarSean McBride <sean@rogue-research.com>
Merge-request: !4129
parents 0f275d76 77183b27
......@@ -29,6 +29,7 @@ vtk_add_test_cxx(${vtk-module}CxxTests tests
TestDistancePolyDataFilter.cxx
TestGraphWeightEuclideanDistanceFilter.cxx,NO_VALID
TestImageDataToPointSet.cxx,NO_VALID
TestIntersectionPolyDataFilter4.cxx,NO_VALID
TestIntersectionPolyDataFilter3.cxx
TestIntersectionPolyDataFilter2.cxx,NO_VALID
TestIntersectionPolyDataFilter.cxx
......
/*=========================================================================
Program: Visualization Toolkit
Module: TestIntersectionPolyDataFilter4.cxx
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
#include <vtkIntersectionPolyDataFilter.h>
#include <vtkNew.h>
#include <vtkSphereSource.h>
#include <vtkTriangleFilter.h>
// This test exercises the conditions that previously led to an out-of-bounds
// memory access when computing the intersection between two surfaces, at least
// one of which was not entirely enclosed (the sphere ending at Theta=305 below).
int TestIntersectionPolyDataFilter4(int, char *[])
{
vtkNew<vtkSphereSource> sphere1;
sphere1->SetStartTheta(0.0);
sphere1->SetEndTheta(305.0);
vtkNew<vtkTriangleFilter> triangle1;
triangle1->SetInputConnection(sphere1->GetOutputPort());
vtkNew<vtkSphereSource> sphere2;
sphere2->SetCenter(0.2, 0.0, 0.0);
vtkNew<vtkTriangleFilter> triangle2;
triangle2->SetInputConnection(sphere2->GetOutputPort());
vtkNew<vtkIntersectionPolyDataFilter> interFilter;
interFilter->SetInputConnection(0, triangle1->GetOutputPort());
interFilter->SetInputConnection(1, triangle2->GetOutputPort());
interFilter->SplitFirstOutputOn();
interFilter->SplitSecondOutputOn();
interFilter->Update();
return EXIT_SUCCESS;
}
......@@ -115,7 +115,7 @@ protected:
//Get individual polygon loop of splitting cell
int GetSingleLoop(vtkPolyData *pd,simPolygon *loop, vtkIdType nextCell,
bool *interPtBool, bool *lineBool);
std::vector<bool> &interPtBool, std::vector<bool> &lineBool);
//Follow a loop orienation to iterate around a split polygon
int FollowLoopOrientation(vtkPolyData *pd, simPolygon *loop,
......@@ -1418,23 +1418,13 @@ int vtkIntersectionPolyDataFilter::Impl
vtkSmartPointer<vtkIdList> cellPoints = vtkSmartPointer<vtkIdList>::New();
simPoint nextPt;
vtkIdType nextCell;
bool *ptBool;
ptBool = new bool[pd->GetNumberOfPoints()];
bool *lineBool;
lineBool = new bool[pd->GetNumberOfCells()];
int numPoints = pd->GetNumberOfPoints();
int numCells = pd->GetNumberOfCells();
for (vtkIdType ptId = 0; ptId < numPoints; ptId++)
{
ptBool[ptId] = false;
}
vtkDebugWithObjectMacro(this->ParentFilter, <<"Number Of Cells: "<<numCells);
for (vtkIdType lineId = 0; lineId < numCells; lineId++)
{
lineBool[lineId] = false;
}
std::vector<bool> ptBool(numPoints, false);
// Add one for the cell that could be added in GetSingleLoop
std::vector<bool> lineBool(numCells+1, false);
//For each point in triangle and additional lines
for (vtkIdType ptId = 0; ptId < numPoints; ptId++)
......@@ -1455,8 +1445,6 @@ int vtkIntersectionPolyDataFilter::Impl
//Get one loop for untouched point
if (this->GetSingleLoop(pd, &interloop, nextCell, ptBool, lineBool) != 1)
{
delete [] ptBool;
delete [] lineBool;
return 0;
}
//Add new loop
......@@ -1481,8 +1469,6 @@ int vtkIntersectionPolyDataFilter::Impl
//Get single loop if the line is still untouched
if (this->GetSingleLoop(pd, &interloop, nextCell, ptBool, lineBool) != 1)
{
delete [] ptBool;
delete [] lineBool;
return 0;
}
//Add new loop to loops
......@@ -1490,9 +1476,6 @@ int vtkIntersectionPolyDataFilter::Impl
}
}
delete [] ptBool;
delete [] lineBool;
return 1;
}
......@@ -1500,7 +1483,7 @@ int vtkIntersectionPolyDataFilter::Impl
int vtkIntersectionPolyDataFilter::Impl
::GetSingleLoop(vtkPolyData *pd, simPolygon *loop, vtkIdType nextCell,
bool *interPtBool, bool *lineBool)
std::vector<bool> &interPtBool, std::vector<bool> &lineBool)
{
int intertype = 0;
vtkSmartPointer<vtkIdList> pointCells = vtkSmartPointer<vtkIdList>::New();
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment