Commit cc27344a authored by Brad King's avatar Brad King
Browse files

BUG: Fixed empty data crash in compression blocks.

parent bcf86dad
......@@ -23,7 +23,7 @@
#include "vtkBase64InputStream.h"
#include "vtkDataCompressor.h"
vtkCxxRevisionMacro(vtkXMLDataParser, "1.7");
vtkCxxRevisionMacro(vtkXMLDataParser, "1.8");
vtkStandardNewMacro(vtkXMLDataParser);
vtkCxxSetObjectMacro(vtkXMLDataParser, Compressor, vtkDataCompressor);
......@@ -428,24 +428,34 @@ void vtkXMLDataParser::ReadCompressionHeader()
this->PartialLastBlockUncompressedSize = headerBuffer[2];
// Allocate the size and offset parts of the header.
if(this->BlockCompressedSizes) { delete [] this->BlockCompressedSizes; }
this->BlockCompressedSizes = new unsigned int[this->NumberOfBlocks];
if(this->BlockStartOffsets) { delete [] this->BlockStartOffsets; }
this->BlockStartOffsets = new unsigned long[this->NumberOfBlocks];
buffer = reinterpret_cast<unsigned char*>(&this->BlockCompressedSizes[0]);
// Read the compressed block sizes.
unsigned long len = this->NumberOfBlocks*sizeof(unsigned int);
if(this->DataStream->Read(buffer, len) < len)
if(this->BlockCompressedSizes)
{
vtkErrorMacro("Error reading compression header.");
return;
delete [] this->BlockCompressedSizes;
this->BlockCompressedSizes = 0;
}
if(this->BlockStartOffsets)
{
delete [] this->BlockStartOffsets;
this->BlockStartOffsets = 0;
}
if(this->NumberOfBlocks > 0)
{
this->BlockCompressedSizes = new unsigned int[this->NumberOfBlocks];
this->BlockStartOffsets = new unsigned long[this->NumberOfBlocks];
buffer = reinterpret_cast<unsigned char*>(&this->BlockCompressedSizes[0]);
// Byte swap the sizes to make sure the values are correct.
this->PerformByteSwap(buffer, this->NumberOfBlocks, sizeof(unsigned int));
// Read the compressed block sizes.
unsigned long len = this->NumberOfBlocks*sizeof(unsigned int);
if(this->DataStream->Read(buffer, len) < len)
{
vtkErrorMacro("Error reading compression header.");
return;
}
// Byte swap the sizes to make sure the values are correct.
this->PerformByteSwap(buffer, this->NumberOfBlocks, sizeof(unsigned int));
}
this->DataStream->EndReading();
......@@ -532,6 +542,12 @@ unsigned long vtkXMLDataParser::ReadCompressedData(unsigned char* data,
unsigned long offset,
unsigned long length)
{
// Make sure there are data.
if(length == 0)
{
return 0;
}
// Find the begin and end offsets into the data.
unsigned long beginOffset = offset;
unsigned long endOffset = offset+length;
......
Supports Markdown
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