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 @@
#include "vtkMath.h"
#include "vtkCell.h"
#include "vtkCellArray.h"
#include "vtkCellIterator.h"
#include "vtkEdgeTable.h"
#include "vtkIdList.h"
#include "vtkInformation.h"
......@@ -345,29 +346,26 @@ int vtkLoopSubdivisionFilter::RequestData(
vtkPolyData *input = vtkPolyData::SafeDownCast(
vtkCellArray *polys = input->GetPolys();
int hasTris = 0;
vtkIdType numPts = 0, *pts = 0;
while (polys->GetNextCell(numPts, pts))
if (numPts == 3)
// Superclass checks for empty cell array, so let's just make sure that the
// cells present, if any, are triangles.
bool hasOnlyTris = true;
vtkCellIterator *it = input->NewCellIterator();
for (it->InitTraversal(); !it->IsDoneWithTraversal(); it->GoToNextCell())
if (input->IsTriangle(pts[0], pts[1], pts[2]))
if (it->GetCellType() != VTK_TRIANGLE)
hasTris = 1;
hasOnlyTris = false;
if (!hasTris)
if (!hasOnlyTris)
vtkWarningMacro("vtkLoopSubdivisionFilter only operates on triangles, but this data set has no triangles to operate on.")
return 0;
vtkErrorMacro("vtkLoopSubdivisionFilter only operates on triangles, but "
"this data set has other cell types present.")
return 1;
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