Crash in Exodus reader's ReadMetaDataFile
This issue was created automatically from an original Mantis Issue. Further discussion may take place here.
I have a .bin file that I want to open with the raw image reader. Paraview doesn't recognize the .bin extension though, so it presents me with a list of readers to choose from. In order to compile the list of available readers, paraview calls CanReadFile("test.bin") on every reader. When it gets to the vtkExodusFileSeriesReader there is a crash.
It goes:
-
vtkFileSeriesReader::CanReadFile("test.bin")
-
if (this->UseMetaFile) <-- true
-
vtkFileSeriesReader::ReadMetaDataFile("test.bin")
This routine opens test.bin as an ifstream and reads the contents into a std::string: metafile >> fname; Now fname contains garbage, because this is a raw image file.
- vtkExodusIIReader::CanReadFile()
This routine fails to open the file, tries to create an error message and calls strcpy on the garbage value and crashes.
So this can be avoided if we check that metafile >> fname reads only ascii characters. One solution is adding:
for (size_t i = 0; i < fname.size(); ++i)
{
if (static_cast<unsigned char>(fname[i]) > 127)
{
return 0;
}
}
Is it ok to call metafile >> fname on binary files? We could read metafile character by character instead of checking fname after the fact. Are there any scenarios where metafile uses a non ascii text encoding that should be supported?