[Insight-developers] Bug in MetaIO

Karthik Krishnan karthik.krishnan at kitware.com
Thu Sep 18 15:25:28 EDT 2008


Hello:

There is a bug in Insight/Utilities/metaImage.cxx that causes memory
leaks and beyond file stream buffer access when reading out compressed
meta images as lists.

To reproduce the error:

  metaImageWriter->SetFileName( "Test3DImage-%d.mhd" );
  metaImageWriter->UseCompressionOn();
  metaImageWriter->Write();
  metaImageReader->SetFileName("Test3DImage-%d.mhd" );
  metaImageReader->Read(); // CRASH

The bug is caused by repeated access of the m_CompressedDataSize
variable in lines 2601-2612. The size is read in for the first file in
the list and assumed to be the same for all the files in the list.
That will not work for the compressed size, since each slice generally
compresses to different lengths.

    if(m_CompressedDataSize==0)
      {
      _fstream->seekg(0, METAIO_STREAM::ios::end);
      m_CompressedDataSize = _fstream->tellg();
      _fstream->seekg(0, METAIO_STREAM::ios::beg);
      }

I'm going to reset the the compressedDataSize after the read is done,
so it is determined from the file-size for the next file in the list.

Thanks

-- 
Karthik Krishnan
R&D Engineer,
Kitware Inc.
Ph: 518 371 3971 x119
Fax: 518 371 3971


More information about the Insight-developers mailing list