From Paul Martz, "Attached are some minor plugin fixes. PNM, RGB, and JPEG would all crash if attempting to read an empty file, and FLT would go into an infinite loop. All are fixed with this change.

I also fixed some return values for a couple of these, changing FILE_NOT_HANDLED to ERROR_IN_READING_FILE where appropriate."
This commit is contained in:
Robert Osfield 2008-05-09 11:27:03 +00:00
parent 01f58ffbb2
commit 61e3285ffc
4 changed files with 12 additions and 3 deletions

View File

@ -299,6 +299,9 @@ class FLTReaderWriter : public ReaderWriter
opcode_type opcode = (opcode_type)dataStream.readUInt16(); opcode_type opcode = (opcode_type)dataStream.readUInt16();
size_type size = (size_type)dataStream.readUInt16(); size_type size = (size_type)dataStream.readUInt16();
if (size==0)
return ReadResult::ERROR_IN_READING_FILE;
// variable length record complete? // variable length record complete?
if (!continuationBuffer.empty() && opcode!=CONTINUATION_OP) if (!continuationBuffer.empty() && opcode!=CONTINUATION_OP)
{ {

View File

@ -614,6 +614,9 @@ class ReaderWriterJPEG : public osgDB::ReaderWriter
{ {
WriteResult::WriteStatus write_JPEG_file (std::ostream &fout,int image_width,int image_height,JSAMPLE* image_buffer,int quality = 100) const WriteResult::WriteStatus write_JPEG_file (std::ostream &fout,int image_width,int image_height,JSAMPLE* image_buffer,int quality = 100) const
{ {
if ( (image_width == 0) || (image_height == 0) )
return WriteResult::ERROR_IN_WRITING_FILE;
/* This struct contains the JPEG compression parameters and pointers to /* This struct contains the JPEG compression parameters and pointers to
* working space (which is allocated as needed by the JPEG library). * working space (which is allocated as needed by the JPEG library).
* It is possible to have several such structures, representing multiple * It is possible to have several such structures, representing multiple

View File

@ -279,7 +279,8 @@ class ReaderWriterPNM : public osgDB::ReaderWriter
int row; int row;
for (row = 1; row <= 3; row++) for (row = 1; row <= 3; row++)
{ {
fgets(line, 300, fp); if ( fgets(line, 300, fp) == NULL)
break;
char *cp = line; char *cp = line;
while (*cp && isspace(*cp)) while (*cp && isspace(*cp))
@ -326,7 +327,7 @@ class ReaderWriterPNM : public osgDB::ReaderWriter
ppmtype < 1 || ppmtype > 6) ppmtype < 1 || ppmtype > 6)
{ {
fclose(fp); fclose(fp);
return ReadResult::FILE_NOT_HANDLED; return ReadResult::ERROR_IN_READING_FILE;
} }
int pixelFormat = 0; int pixelFormat = 0;

View File

@ -168,6 +168,8 @@ static rawImageRec *RawImageOpen(std::istream& fin)
} }
fin.read((char*)raw,12); fin.read((char*)raw,12);
if (!fin.good())
return NULL;
if (raw->swapFlag) if (raw->swapFlag)
{ {
@ -459,7 +461,7 @@ class ReaderWriterRGB : public osgDB::ReaderWriter
if( (raw = RawImageOpen(fin)) == NULL ) if( (raw = RawImageOpen(fin)) == NULL )
{ {
return ReadResult::FILE_NOT_HANDLED; return ReadResult::ERROR_IN_READING_FILE;
} }
int s = raw->sizeX; int s = raw->sizeX;