[vtk-developers] More bugs in vtkDataReader.cxx

Prabhu Ramachandran prabhu at aero.iitm.ernet.in
Tue Apr 17 04:53:05 EDT 2001


hi,

While reading a VTK binary data file I detected the foll. bug with the
vtkDataReader.cxx code.  If you try doing something like this:

   >>> from vtkpython import *
   >>> r = vtkStructuredPointsReader ()
   >>> r.SetFileName ("ironProt.vtk")
   >>> print r.GetNumberOfScalarsInFile ()
   Terminated

It goes into an infinite loop never returning anything and the
interpreter has to be killed.  This happens due to the following code
in vtkDataReader.cxx

<line num 222>
// Internal function to read in a line up to 256 characters.
// Returns zero if there was an error.
int vtkDataReader::ReadLine(char result[256])
{
  this->IS->getline(result,256);
  if (this->IS->eof()) 
    {
    return 0;
    }
  return 1;
}

This wont work when the line is longer than 256 chars (which usually
is true when you have binary data).  The problem will vanish if one
uses code like this instead.

int vtkDataReader::ReadLine(char result[256])
{
  this->IS->getline(result,256);
  if (this->IS->fail())
    {
    if (this->IS->eof()) 
      {
      return 0;
      }
    if (this->IS->gcount() == 255)
      {
      // Read 256 chars; ignoring the rest of the line.
      this->IS->clear ();
      this->IS->ignore (VTK_INT_MAX, '\n');
      }
    }
  return 1;
}

I propose to test and commit this change.  The ReadLine function is
used only to read the header and to 'Characterize' the file, so I
doubt that this change will introduce other errors.

Let me know if you have any objections or suggestions.

thanks,
prabhu




More information about the vtk-developers mailing list