Commit dca54f17 authored by David C. Lonie's avatar David C. Lonie
Browse files

Fix crash in LoopSubdivisionFilter.

If this filter is given a dataset containing cells that are not
triangles, it will cause a segfault. This patch modifies the check
for cell types to fail if any non-triangle cell is found, rather
than just checking that some triangles exist.
parent b3ca86b8
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
#include "vtkMath.h" #include "vtkMath.h"
#include "vtkCell.h" #include "vtkCell.h"
#include "vtkCellArray.h" #include "vtkCellArray.h"
#include "vtkCellIterator.h"
#include "vtkEdgeTable.h" #include "vtkEdgeTable.h"
#include "vtkIdList.h" #include "vtkIdList.h"
#include "vtkInformation.h" #include "vtkInformation.h"
...@@ -345,29 +346,26 @@ int vtkLoopSubdivisionFilter::RequestData( ...@@ -345,29 +346,26 @@ int vtkLoopSubdivisionFilter::RequestData(
vtkPolyData *input = vtkPolyData::SafeDownCast( vtkPolyData *input = vtkPolyData::SafeDownCast(
inInfo->Get(vtkDataObject::DATA_OBJECT())); inInfo->Get(vtkDataObject::DATA_OBJECT()));
vtkCellArray *polys = input->GetPolys();
int hasTris = 0;
vtkIdType numPts = 0, *pts = 0;
input->BuildLinks(); // Superclass checks for empty cell array, so let's just make sure that the
// cells present, if any, are triangles.
polys->InitTraversal(); bool hasOnlyTris = true;
while (polys->GetNextCell(numPts, pts)) vtkCellIterator *it = input->NewCellIterator();
for (it->InitTraversal(); !it->IsDoneWithTraversal(); it->GoToNextCell())
{ {
if (numPts == 3) if (it->GetCellType() != VTK_TRIANGLE)
{ {
if (input->IsTriangle(pts[0], pts[1], pts[2])) hasOnlyTris = false;
{ break;
hasTris = 1;
break;
}
} }
} }
it->Delete();
if (!hasTris) if (!hasOnlyTris)
{ {
vtkWarningMacro("vtkLoopSubdivisionFilter only operates on triangles, but this data set has no triangles to operate on.") vtkErrorMacro("vtkLoopSubdivisionFilter only operates on triangles, but "
return 0; "this data set has other cell types present.")
return 1;
} }
return this->Superclass::RequestData(request, inputVector, outputVector); return this->Superclass::RequestData(request, inputVector, outputVector);
......
Markdown is supported
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