Commit 55a7f9d0 authored by Bill Lorensen's avatar Bill Lorensen
Browse files

BUG: 0013057: bad xml input to XML Reader's causes exception

Added error checks in XMLDataParser to return a failing status for bad
headers. Added a test that reads bad image data, poly data,
rectilinear grid data, uniform data and unstructured grid data.

Change-Id: I2284cbe0cebb1934994096bbe64e2492062d33c9
parent 8bc22e48
......@@ -8,4 +8,21 @@ vtk_add_test_cxx(${vtk-module}CxxTests tests
TestDataObjectXMLIO.cxx,NO_VALID
)
# Each of these most be added in a separate vtk_add_test_cxx
vtk_add_test_cxx(${vtk-module}CxxTests tests
TestXMLReaderBadImageData,TestXMLReaderBadData.cxx,NO_VALID,NO_OUTPUT "DATA{${VTK_TEST_INPUT_DIR}/badImageData.xml}"
)
vtk_add_test_cxx(${vtk-module}CxxTests tests
TestXMLReaderBadPolyData,TestXMLReaderBadData.cxx,NO_VALID,NO_OUTPUT "DATA{${VTK_TEST_INPUT_DIR}/badPolyData.xml}"
)
vtk_add_test_cxx(${vtk-module}CxxTests tests
TestXMLReaderBadRectilinearGridData,TestXMLReaderBadData.cxx,NO_VALID,NO_OUTPUT "DATA{${VTK_TEST_INPUT_DIR}/badRectilinearGridData.xml}"
)
vtk_add_test_cxx(${vtk-module}CxxTests tests
TestXMLReaderBadUnstucturedGridData,TestXMLReaderBadData.cxx,NO_VALID,NO_OUTPUT "DATA{${VTK_TEST_INPUT_DIR}/badUnstructuredGridData.xml}"
)
vtk_add_test_cxx(${vtk-module}CxxTests tests
TestXMLReaderBadUniformGridData,TestXMLReaderBadData.cxx,NO_VALID,NO_OUTPUT "DATA{${VTK_TEST_INPUT_DIR}/badUniformGridData.xml}"
)
vtk_test_cxx_executable(${vtk-module}CxxTests tests)
/*=========================================================================
Program: Visualization Toolkit
Module: TestXMLReaderBadData.cxx
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
#include <vtkSmartPointer.h>
#include <vtkXMLGenericDataObjectReader.h>
int TestXMLReaderBadData(int argc, char* argv[])
{
// Verify input arguments
if(argc < 2)
{
std::cout << "Usage: " << argv[0]
<< " Filename" << std::endl;
return EXIT_FAILURE;
}
std::string inputFilename = argv[1];
// Read the file
vtkSmartPointer<vtkXMLGenericDataObjectReader> reader =
vtkSmartPointer<vtkXMLGenericDataObjectReader>::New();
reader->SetFileName(inputFilename.c_str());
reader->Update();
return EXIT_SUCCESS;
}
......@@ -466,7 +466,7 @@ void vtkXMLDataParser::PerformByteSwap(void* data, size_t numWords,
}
//----------------------------------------------------------------------------
void vtkXMLDataParser::ReadCompressionHeader()
int vtkXMLDataParser::ReadCompressionHeader()
{
vtksys::auto_ptr<vtkXMLDataHeader>
ch(vtkXMLDataHeader::New(this->HeaderType, 3));
......@@ -480,7 +480,7 @@ void vtkXMLDataParser::ReadCompressionHeader()
{
vtkErrorMacro("Error reading beginning of compression header. Read "
<< r << " of " << headerSize << " bytes.");
return;
return 0;
}
// Byte swap the header to make sure the values are correct.
......@@ -513,7 +513,7 @@ void vtkXMLDataParser::ReadCompressionHeader()
if(this->DataStream->Read(ch->Data(), len) < len)
{
vtkErrorMacro("Error reading compression header.");
return;
return 0;
}
// Byte swap the sizes to make sure the values are correct.
......@@ -532,6 +532,7 @@ void vtkXMLDataParser::ReadCompressionHeader()
this->BlockStartOffsets[i] = offset;
offset += sz;
}
return 1;
}
//----------------------------------------------------------------------------
......@@ -829,7 +830,11 @@ size_t vtkXMLDataParser::ReadBinaryData(void* in_buffer,
size_t actualWords;
if(this->Compressor)
{
this->ReadCompressionHeader();
if (!this->ReadCompressionHeader())
{
vtkErrorMacro("ReadCompressionHeader failed. Aborting read.");
return 0;
}
this->DataStream->StartReading();
actualWords = this->ReadCompressedData(d, startWord, numWords, wordSize);
this->DataStream->EndReading();
......
......@@ -162,7 +162,7 @@ protected:
void PerformByteSwap(void* data, size_t numWords, size_t wordSize);
// Data reading methods.
void ReadCompressionHeader();
int ReadCompressionHeader();
size_t FindBlockSize(vtkTypeUInt64 block);
int ReadBlock(vtkTypeUInt64 block, unsigned char* buffer);
unsigned char* ReadBlock(vtkTypeUInt64 block);
......
107c7f224b620b5d45be4205e10909c5
7ccfa954bddb31a78747541652ad4e0f
b2552ead2651bc11d87999664c1c38f8
ab20fcca25633f630695a9aea048c5e0
74125787cd4254fba57b6af3d099c2b7
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