[vtk-developers] Handling invalid vtp files

David Doria daviddoria+vtk at gmail.com
Sat Feb 13 18:18:33 EST 2010


I noticed this problem a while back:
http://public.kitware.com/Bug/view.php?id=9814

The demo file I added to the bug contains a triangle cell but 0 points.
Clearly this is a bad situation. It doesn't crash the XMLPolyDataReader, but
if you load the file in Paraview, the call stack shows:

vtkDataArrayTemplate<float>::GetTuple (line 613)
vtkPoints::GetPoint
vtkPolygon::ComputeNormal
PVGeometryFilter::ExecuteCellNormals

The problem occurs on line 610 of vtkDataArrayTemplate.txx - 't' is NULL, so
then on line 613 it segfaults.

Is this type of thing where we would want to allow a crash (the assumption
being that only good data files are loaded)? Or could we change:

template <class T>
void vtkDataArrayTemplate<T>::GetTuple(vtkIdType i, double* tuple)
{
  T* t = this->Array + this->NumberOfComponents*i;
  for(int j=0; j < this->NumberOfComponents; ++j)
    {
    tuple[j] = static_cast<double>(t[j]);
    }
}

to something like:

template <class T>
void vtkDataArrayTemplate<T>::GetTuple(vtkIdType i, double* tuple)
{
  T* t = this->Array + this->NumberOfComponents*i;

  if(!t)
    {
    return;
    }

  for(int j=0; j < this->NumberOfComponents; ++j)
    {
    tuple[j] = static_cast<double>(t[j]);
    }
}

Thanks,

David
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtk-developers/attachments/20100213/b3dbc471/attachment.html>


More information about the vtk-developers mailing list