% July 1992 %
% %
% %
-% Copyright 1999-2016 ImageMagick Studio LLC, a non-profit organization %
+% Copyright 1999-2017 ImageMagick Studio LLC, a non-profit organization %
% dedicated to making software imaging solutions freely available. %
% %
% You may not use this file except in compliance with the License. You may %
% obtain a copy of the License at %
% %
-% http://www.imagemagick.org/script/license.php %
+% https://www.imagemagick.org/script/license.php %
% %
% Unless required by applicable law or agreed to in writing, software %
% distributed under the License is distributed on an "AS IS" BASIS, %
/*
Read record header.
*/
- img_offset=(ssize_t) ((int) ReadBlobMSBLong(image));
+ img_offset=(ssize_t) ReadBlobMSBSignedLong(image);
attributes=(unsigned char) ReadBlobByte(image);
(void) attributes;
count=ReadBlob(image,3,(unsigned char *) tag);
ThrowReaderException(CorruptImageError,"CorruptImage");
if (pdb_info.number_records > 1)
{
- comment_offset=(ssize_t) ((int) ReadBlobMSBLong(image));
+ comment_offset=(ssize_t) ReadBlobMSBSignedLong(image);
attributes=(unsigned char) ReadBlobByte(image);
count=ReadBlob(image,3,(unsigned char *) tag);
if (count != 3 || memcmp(tag,"\x6f\x80\x01",3) != 0)
if (count != sizeof(pdb_image.name))
ThrowReaderException(CorruptImageError,"ImproperImageHeader");
pdb_image.version=ReadBlobByte(image);
- pdb_image.type=(unsigned char) ((int) ReadBlobByte(image));
+ pdb_image.type=(unsigned char) (ReadBlobByte(image));
pdb_image.reserved_1=ReadBlobMSBLong(image);
pdb_image.note=ReadBlobMSBLong(image);
pdb_image.x_last=(short) ReadBlobMSBShort(image);
image->columns=(size_t) pdb_image.width;
image->rows=(size_t) pdb_image.height;
image->depth=8;
- status=SetImageExtent(image,image->columns,image->rows,exception);
- if (status == MagickFalse)
- return(DestroyImageList(image));
image->storage_class=PseudoClass;
bits_per_pixel=pdb_image.type == 0 ? 2UL : pdb_image.type == 2 ? 4UL : 1UL;
one=1;
(void) CloseBlob(image);
return(GetFirstImageInList(image));
}
+ status=SetImageExtent(image,image->columns,image->rows,exception);
+ if (status == MagickFalse)
+ return(DestroyImageList(image));
packets=(bits_per_pixel*image->columns+7)/8;
- pixels=(unsigned char *) AcquireQuantumMemory(packets+256UL,image->rows*
+ pixels=(unsigned char *) AcquireQuantumMemory(packets+257UL,image->rows*
sizeof(*pixels));
if (pixels == (unsigned char *) NULL)
ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
case 0:
{
image->compression=NoCompression;
- count=(ssize_t) ReadBlob(image, packets * image -> rows, pixels);
+ count=(ssize_t) ReadBlob(image,packets*image->rows,pixels);
break;
}
case 1:
{
image->compression=RLECompression;
- if (!DecodeImage(image, pixels, packets * image -> rows))
- ThrowReaderException( CorruptImageError, "RLEDecoderError" );
+ if (!DecodeImage(image,pixels,packets*image->rows))
+ {
+ pixels=(unsigned char *) RelinquishMagickMemory(pixels);
+ ThrowReaderException(CorruptImageError,"RLEDecoderError");
+ }
break;
}
default:
+ {
+ pixels=(unsigned char *) RelinquishMagickMemory(pixels);
ThrowReaderException(CorruptImageError,
- "UnrecognizedImageCompressionType" );
+ "UnrecognizedImageCompressionType");
+ }
}
p=pixels;
switch (bits_per_pixel)
break;
}
default:
+ {
+ pixels=(unsigned char *) RelinquishMagickMemory(pixels);
ThrowReaderException(CorruptImageError,"ImproperImageHeader");
+ }
}
pixels=(unsigned char *) RelinquishMagickMemory(pixels);
if (EOFBlob(image) != MagickFalse)
length;
num_pad_bytes = (size_t) (comment_offset - TellBlob( image ));
- while (num_pad_bytes--) ReadBlobByte( image );
+ while (num_pad_bytes-- != 0)
+ {
+ int
+ c;
+
+ c=ReadBlobByte(image);
+ if (c == EOF)
+ break;
+ }
/*
Read comment.
pdb_image.width=(short) (16*(image->columns/16+1));
pdb_image.height=(short) image->rows;
packets=((bits_per_pixel*image->columns+7)/8);
- runlength=(unsigned char *) AcquireQuantumMemory(4UL*packets,
+ runlength=(unsigned char *) AcquireQuantumMemory(9UL*packets,
image->rows*sizeof(*runlength));
if (runlength == (unsigned char *) NULL)
ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed");
- buffer=(unsigned char *) AcquireQuantumMemory(2*256,sizeof(*buffer));
+ buffer=(unsigned char *) AcquireQuantumMemory(512,sizeof(*buffer));
if (buffer == (unsigned char *) NULL)
ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed");
- packet_size=(size_t) (image->depth > 8 ? 2: 1);
+ packet_size=(size_t) (image->depth > 8 ? 2 : 1);
scanline=(unsigned char *) AcquireQuantumMemory(image->columns,packet_size*
sizeof(*scanline));
if (scanline == (unsigned char *) NULL)
quantum_info=AcquireQuantumInfo(image_info,image);
if (quantum_info == (QuantumInfo *) NULL)
ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed");
+ status=SetQuantumDepth(image,quantum_info,image->depth > 8 ? 16 : 8);
bits=8/(int) bits_per_pixel-1; /* start at most significant bits */
literal=0;
repeat=0;