% July 1992 %
% %
% %
-% Copyright 1999-2015 ImageMagick Studio LLC, a non-profit organization %
+% Copyright 1999-2018 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, %
/*
Define declarations.
*/
-#if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__MINGW32__) || defined(__MINGW64__)
+#if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__MINGW32__)
#define BI_RGB 0
#define BI_RLE8 1
#define BI_BITFIELDS 3
p++;
size=(size_t)strtol(p,&q,10);
- if (p == q || size < 16 || size > 256)
- return((Image *) NULL);
+ if ((p == q) || (size < 16) || (size > 256))
+ return((Image *) NULL);
p=q;
sizes[i++]=size;
MagickBooleanType
status;
+ MagickSizeType
+ extent;
+
register ssize_t
i,
x;
Open image file.
*/
assert(image_info != (const ImageInfo *) NULL);
- assert(image_info->signature == MagickSignature);
+ assert(image_info->signature == MagickCoreSignature);
(void) LogMagickEvent(CoderEvent,GetMagickModule(),"%s",image_info->filename);
assert(exception != (ExceptionInfo *) NULL);
- assert(exception->signature == MagickSignature);
+ assert(exception->signature == MagickCoreSignature);
image=AcquireImage(image_info,exception);
status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
if (status == MagickFalse)
((icon_file.resource_type != 1) && (icon_file.resource_type != 2)) ||
(icon_file.count > MaxIcons))
ThrowReaderException(CorruptImageError,"ImproperImageHeader");
+ extent=0;
for (i=0; i < icon_file.count; i++)
{
icon_file.directory[i].width=(unsigned char) ReadBlobByte(image);
icon_file.directory[i].size=ReadBlobLSBLong(image);
icon_file.directory[i].offset=ReadBlobLSBLong(image);
if (EOFBlob(image) != MagickFalse)
- {
- ThrowFileException(exception,CorruptImageError,"UnexpectedEndOfFile",
- image->filename);
- break;
- }
+ break;
+ extent=MagickMax(extent,icon_file.directory[i].size);
}
+ if ((EOFBlob(image) != MagickFalse) || (extent > GetBlobSize(image)))
+ ThrowReaderException(CorruptImageError,"UnexpectedEndOfFile");
one=1;
for (i=0; i < icon_file.count; i++)
{
if (offset < 0)
ThrowReaderException(CorruptImageError,"ImproperImageHeader");
icon_info.size=ReadBlobLSBLong(image);
- icon_info.width=(unsigned char) ((int) ReadBlobLSBLong(image));
- icon_info.height=(unsigned char) ((int) ReadBlobLSBLong(image)/2);
+ icon_info.width=(unsigned char) ReadBlobLSBSignedLong(image);
+ icon_info.height=(unsigned char) (ReadBlobLSBSignedLong(image)/2);
icon_info.planes=ReadBlobLSBShort(image);
icon_info.bits_per_pixel=ReadBlobLSBShort(image);
if (EOFBlob(image) != MagickFalse)
Icon image encoded as a compressed PNG image.
*/
length=icon_file.directory[i].size;
+ if ((length < 16) || (~length < 16))
+ ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
png=(unsigned char *) AcquireQuantumMemory(length+16,sizeof(*png));
if (png == (unsigned char *) NULL)
ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
- (void) CopyMagickMemory(png,"\211PNG\r\n\032\n\000\000\000\015",12);
+ (void) memcpy(png,"\211PNG\r\n\032\n\000\000\000\015",12);
png[12]=(unsigned char) icon_info.planes;
png[13]=(unsigned char) (icon_info.planes >> 8);
png[14]=(unsigned char) icon_info.bits_per_pixel;
png[15]=(unsigned char) (icon_info.bits_per_pixel >> 8);
- count=ReadBlob(image,length-16,png+16);
- icon_image=(Image *) NULL;
- if (count > 0)
+ count=ReadBlob(image,length,png+16);
+ if (count != (ssize_t) length)
{
- read_info=CloneImageInfo(image_info);
- (void) CopyMagickString(read_info->magick,"PNG",MagickPathExtent);
- icon_image=BlobToImage(read_info,png,length+16,exception);
- read_info=DestroyImageInfo(read_info);
+ png=(unsigned char *) RelinquishMagickMemory(png);
+ ThrowReaderException(CorruptImageError,
+ "InsufficientImageDataInFile");
}
+ read_info=CloneImageInfo(image_info);
+ (void) CopyMagickString(read_info->magick,"PNG",MagickPathExtent);
+ icon_image=BlobToImage(read_info,png,length+16,exception);
+ read_info=DestroyImageInfo(read_info);
png=(unsigned char *) RelinquishMagickMemory(png);
if (icon_image == (Image *) NULL)
- {
- if (count != (ssize_t) (length-16))
- ThrowReaderException(CorruptImageError,
- "InsufficientImageDataInFile");
- image=DestroyImageList(image);
- return((Image *) NULL);
- }
+ return(DestroyImageList(image));
DestroyBlob(icon_image);
icon_image->blob=ReferenceBlob(image->blob);
ReplaceImageInList(&image,icon_image);
icon_info.x_pixels=ReadBlobLSBLong(image);
icon_info.y_pixels=ReadBlobLSBLong(image);
icon_info.number_colors=ReadBlobLSBLong(image);
+ if (icon_info.number_colors > GetBlobSize(image))
+ ThrowReaderException(CorruptImageError,"InsufficientImageDataInFile");
icon_info.colors_important=ReadBlobLSBLong(image);
image->alpha_trait=BlendPixelTrait;
image->columns=(size_t) icon_file.directory[i].width;
if (image->rows == 0)
image->rows=256;
image->depth=icon_info.bits_per_pixel;
+ if (image->depth > 16)
+ image->depth=8;
if (image->debug != MagickFalse)
{
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
{
image->storage_class=PseudoClass;
image->colors=icon_info.number_colors;
- if (image->colors == 0)
+ if ((image->colors == 0) || (image->colors > 256))
image->colors=one << icon_info.bits_per_pixel;
}
if (image->storage_class == PseudoClass)
{
register ssize_t
- i;
+ j;
unsigned char
*icon_colormap;
/*
Read Icon raster colormap.
*/
+ if (image->colors > GetBlobSize(image))
+ ThrowReaderException(CorruptImageError,
+ "InsufficientImageDataInFile");
if (AcquireImageColormap(image,image->colors,exception) ==
MagickFalse)
ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
count=ReadBlob(image,(size_t) (4*image->colors),icon_colormap);
if (count != (ssize_t) (4*image->colors))
- ThrowReaderException(CorruptImageError,
- "InsufficientImageDataInFile");
+ {
+ icon_colormap=(unsigned char *) RelinquishMagickMemory(
+ icon_colormap);
+ ThrowReaderException(CorruptImageError,
+ "InsufficientImageDataInFile");
+ }
p=icon_colormap;
- for (i=0; i < (ssize_t) image->colors; i++)
+ for (j=0; j < (ssize_t) image->colors; j++)
{
- image->colormap[i].blue=(Quantum) ScaleCharToQuantum(*p++);
- image->colormap[i].green=(Quantum) ScaleCharToQuantum(*p++);
- image->colormap[i].red=(Quantum) ScaleCharToQuantum(*p++);
+ image->colormap[j].blue=(Quantum) ScaleCharToQuantum(*p++);
+ image->colormap[j].green=(Quantum) ScaleCharToQuantum(*p++);
+ image->colormap[j].red=(Quantum) ScaleCharToQuantum(*p++);
p++;
}
icon_colormap=(unsigned char *) RelinquishMagickMemory(icon_colormap);
for (x=0; x < (ssize_t) image->columns; x++)
{
byte=(size_t) ReadBlobByte(image);
- SetPixelIndex(image,byte,q);
+ SetPixelIndex(image,(Quantum) byte,q);
q+=GetPixelChannels(image);
}
for (x=0; x < (ssize_t) scanline_pad; x++)
for (x=0; x < (ssize_t) image->columns; x++)
{
byte=(size_t) ReadBlobByte(image);
- byte|=(size_t) (ReadBlobByte(image) << 8);
- SetPixelIndex(image,byte,q);
+ byte|=((size_t) ReadBlobByte(image) << 8);
+ SetPixelIndex(image,(Quantum) byte,q);
q+=GetPixelChannels(image);
}
for (x=0; x < (ssize_t) scanline_pad; x++)
default:
ThrowReaderException(CorruptImageError,"ImproperImageHeader");
}
- if (image_info->ping == MagickFalse)
+ if ((image_info->ping == MagickFalse) &&
+ (icon_info.bits_per_pixel <= 16))
(void) SyncImage(image,exception);
if (icon_info.bits_per_pixel != 32)
{
AcquireNextImage(image_info,image,exception);
if (GetNextImageInList(image) == (Image *) NULL)
{
- image=DestroyImageList(image);
- return((Image *) NULL);
+ status=MagickFalse;
+ break;
}
image=SyncNextImageInList(image);
status=SetImageProgress(image,LoadImagesTag,TellBlob(image),
}
}
(void) CloseBlob(image);
+ if (status == MagickFalse)
+ return(DestroyImageList(image));
return(GetFirstImageInList(image));
}
\f
entry->decoder=(DecodeImageHandler *) ReadICONImage;
entry->encoder=(EncodeImageHandler *) WriteICONImage;
entry->flags^=CoderAdjoinFlag;
- entry->flags|=CoderSeekableStreamFlag;
+ entry->flags|=CoderDecoderSeekableStreamFlag;
+ entry->flags|=CoderEncoderSeekableStreamFlag;
(void) RegisterMagickInfo(entry);
entry=AcquireMagickInfo("ICON","ICO","Microsoft icon");
entry->decoder=(DecodeImageHandler *) ReadICONImage;
entry->encoder=(EncodeImageHandler *) WriteICONImage;
- entry->flags|=CoderSeekableStreamFlag;
+ entry->flags|=CoderDecoderSeekableStreamFlag;
+ entry->flags|=CoderEncoderSeekableStreamFlag;
(void) RegisterMagickInfo(entry);
entry=AcquireMagickInfo("ICON","ICON","Microsoft icon");
entry->decoder=(DecodeImageHandler *) ReadICONImage;
entry->encoder=(EncodeImageHandler *) WriteICONImage;
entry->flags^=CoderAdjoinFlag;
- entry->flags|=CoderSeekableStreamFlag;
+ entry->flags|=CoderDecoderSeekableStreamFlag;
+ entry->flags|=CoderEncoderSeekableStreamFlag;
(void) RegisterMagickInfo(entry);
return(MagickImageCoderSignature);
}
size_t
bytes_per_line,
+ imageListLength,
scanline_pad;
ssize_t
y;
unsigned char
- bit,
- byte,
*pixels;
/*
Open output image file.
*/
assert(image_info != (const ImageInfo *) NULL);
- assert(image_info->signature == MagickSignature);
+ assert(image_info->signature == MagickCoreSignature);
assert(image != (Image *) NULL);
- assert(image->signature == MagickSignature);
+ assert(image->signature == MagickCoreSignature);
(void) LogMagickEvent(CoderEvent,GetMagickModule(),"%s",image->filename);
assert(exception != (ExceptionInfo *) NULL);
- assert(exception->signature == MagickSignature);
+ assert(exception->signature == MagickCoreSignature);
status=OpenBlob(image_info,image,WriteBinaryBlobMode,exception);
if (status == MagickFalse)
return(status);
(void) WriteBlobLSBShort(image,0);
(void) WriteBlobLSBShort(image,1);
(void) WriteBlobLSBShort(image,(unsigned char) scene);
- (void) ResetMagickMemory(&icon_file,0,sizeof(icon_file));
- (void) ResetMagickMemory(&icon_info,0,sizeof(icon_info));
+ (void) memset(&icon_file,0,sizeof(icon_file));
+ (void) memset(&icon_info,0,sizeof(icon_info));
scene=0;
next=(images != (Image *) NULL) ? images : image;
do
} while ((next != (Image *) NULL) && (image_info->adjoin != MagickFalse));
scene=0;
next=(images != (Image *) NULL) ? images : image;
+ imageListLength=GetImageListLength(image);
do
{
if ((next->columns > 255L) && (next->rows > 255L) &&
return(MagickFalse);
}
write_info=CloneImageInfo(image_info);
- (void) CopyMagickString(write_info->filename,"PNG:",MagickPathExtent);
+ (void) CopyMagickString(write_info->magick,"PNG",MagickPathExtent);
+ length=0;
/* Don't write any ancillary chunks except for gAMA */
(void) SetImageArtifact(write_image,"png:include-chunk","none,gama");
png=(unsigned char *) ImageToBlob(write_info,write_image,&length,
exception);
- write_image=DestroyImage(write_image);
+ write_image=DestroyImageList(write_image);
write_info=DestroyImageInfo(write_info);
if (png == (unsigned char *) NULL)
{
}
else
{
- size_t
- one;
-
one=1;
icon_info.file_size+=3*(one << icon_info.bits_per_pixel);
icon_info.offset_bits+=3*(one << icon_info.bits_per_pixel);
images=DestroyImageList(images);
ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed");
}
- (void) ResetMagickMemory(pixels,0,(size_t) icon_info.image_size);
+ (void) memset(pixels,0,(size_t) icon_info.image_size);
switch (icon_info.bits_per_pixel)
{
case 1:
scanline_pad=(((next->columns+31) & ~31)-next->columns) >> 3;
for (y=((ssize_t) next->rows - 1); y >= 0; y--)
{
+ unsigned char
+ bit,
+ byte;
+
p=GetVirtualPixels(next,0,y,next->columns,1,exception);
if (p == (const Quantum *) NULL)
break;
}
if (GetNextImageInList(next) == (Image *) NULL)
break;
- status=SetImageProgress(next,SaveImagesTag,scene++,
- GetImageListLength(next));
+ status=SetImageProgress(next,SaveImagesTag,scene++,imageListLength);
if (status == MagickFalse)
break;
next=SyncNextImageInList(next);