From 18718a9d53419f19f08ed11aee2b2d86f29b650d Mon Sep 17 00:00:00 2001 From: Cristy Date: Sun, 25 Mar 2018 12:45:12 -0400 Subject: [PATCH] ... --- coders/pict.c | 234 +++++++++++++++++++++++--------------------------- 1 file changed, 108 insertions(+), 126 deletions(-) diff --git a/coders/pict.c b/coders/pict.c index 6e76744b6..2922bf885 100644 --- a/coders/pict.c +++ b/coders/pict.c @@ -499,7 +499,7 @@ static unsigned char *DecodeImage(Image *blob,Image *image, if (bytes_per_line > 200) scanline_length=ReadBlobMSBShort(blob); else - scanline_length=1UL*ReadBlobByte(blob); + scanline_length=(size_t) ReadBlobByte(blob); if ((scanline_length >= row_bytes) || (scanline_length == 0)) { (void) ThrowMagickException(exception,GetMagickModule(), @@ -811,12 +811,25 @@ static MagickBooleanType ReadRectangle(Image *image,PICTRectangle *rectangle) static Image *ReadPICTImage(const ImageInfo *image_info, ExceptionInfo *exception) { +#define ThrowPICTException(exception,message) \ +{ \ + if (tile_image != (Image *) NULL) \ + tile_image=DestroyImage(tile_image); \ + if (read_info != (ImageInfo *) NULL) \ + read_info=DestroyImageInfo(read_info); \ + ThrowReaderException((exception),(message)); \ +} + char geometry[MagickPathExtent], header_ole[4]; Image - *image; + *image, + *tile_image; + + ImageInfo + *read_info; int c, @@ -876,6 +889,8 @@ static Image *ReadPICTImage(const ImageInfo *image_info, /* Read PICT header. */ + read_info=(ImageInfo *) NULL; + tile_image=(Image *) NULL; pixmap.bits_per_pixel=0; pixmap.component_count=0; /* @@ -892,31 +907,31 @@ static Image *ReadPICTImage(const ImageInfo *image_info, break; (void) ReadBlobMSBShort(image); /* skip picture size */ if (ReadRectangle(image,&frame) == MagickFalse) - ThrowReaderException(CorruptImageError,"ImproperImageHeader"); + ThrowPICTException(CorruptImageError,"ImproperImageHeader"); while ((c=ReadBlobByte(image)) == 0) ; if (c != 0x11) - ThrowReaderException(CorruptImageError,"ImproperImageHeader"); - version=ReadBlobByte(image); + ThrowPICTException(CorruptImageError,"ImproperImageHeader"); + version=(ssize_t) ReadBlobByte(image); if (version == 2) { c=ReadBlobByte(image); if (c != 0xff) - ThrowReaderException(CorruptImageError,"ImproperImageHeader"); + ThrowPICTException(CorruptImageError,"ImproperImageHeader"); } else if (version != 1) - ThrowReaderException(CorruptImageError,"ImproperImageHeader"); + ThrowPICTException(CorruptImageError,"ImproperImageHeader"); if ((frame.left < 0) || (frame.right < 0) || (frame.top < 0) || (frame.bottom < 0) || (frame.left >= frame.right) || (frame.top >= frame.bottom)) - ThrowReaderException(CorruptImageError,"ImproperImageHeader"); + ThrowPICTException(CorruptImageError,"ImproperImageHeader"); /* Create black canvas. */ flags=0; image->depth=8; - image->columns=1UL*(frame.right-frame.left); - image->rows=1UL*(frame.bottom-frame.top); + image->columns=(size_t) (frame.right-frame.left); + image->rows=(size_t) (frame.bottom-frame.top); image->resolution.x=DefaultResolution; image->resolution.y=DefaultResolution; image->units=UndefinedResolution; @@ -975,11 +990,11 @@ static Image *ReadPICTImage(const ImageInfo *image_info, break; } if (ReadRectangle(image,&frame) == MagickFalse) - ThrowReaderException(CorruptImageError,"ImproperImageHeader"); + ThrowPICTException(CorruptImageError,"ImproperImageHeader"); if (((frame.left & 0x8000) != 0) || ((frame.top & 0x8000) != 0)) break; - image->columns=1UL*(frame.right-frame.left); - image->rows=1UL*(frame.bottom-frame.top); + image->columns=(size_t) (frame.right-frame.left); + image->rows=(size_t) (frame.bottom-frame.top); status=SetImageExtent(image,image->columns,image->rows,exception); if (status == MagickFalse) return(DestroyImageList(image)); @@ -1002,7 +1017,7 @@ static Image *ReadPICTImage(const ImageInfo *image_info, /* Skip pattern definition. */ - pattern=1L*ReadBlobMSBShort(image); + pattern=(ssize_t) ReadBlobMSBShort(image); for (i=0; i < 8; i++) if (ReadBlobByte(image) == EOF) break; @@ -1014,23 +1029,23 @@ static Image *ReadPICTImage(const ImageInfo *image_info, break; } if (pattern != 1) - ThrowReaderException(CorruptImageError,"UnknownPatternType"); + ThrowPICTException(CorruptImageError,"UnknownPatternType"); length=ReadBlobMSBShort(image); if (ReadRectangle(image,&frame) == MagickFalse) - ThrowReaderException(CorruptImageError,"ImproperImageHeader"); + ThrowPICTException(CorruptImageError,"ImproperImageHeader"); if (ReadPixmap(image,&pixmap) == MagickFalse) - ThrowReaderException(CorruptImageError,"ImproperImageHeader"); - image->depth=1UL*pixmap.component_size; + ThrowPICTException(CorruptImageError,"ImproperImageHeader"); + image->depth=(size_t) pixmap.component_size; image->resolution.x=1.0*pixmap.horizontal_resolution; image->resolution.y=1.0*pixmap.vertical_resolution; image->units=PixelsPerInchResolution; (void) ReadBlobMSBLong(image); - flags=1L*ReadBlobMSBShort(image); + flags=(ssize_t) ReadBlobMSBShort(image); length=ReadBlobMSBShort(image); for (i=0; i <= (ssize_t) length; i++) (void) ReadBlobMSBLong(image); - width=1UL*(frame.bottom-frame.top); - height=1UL*(frame.right-frame.left); + width=(size_t) (frame.bottom-frame.top); + height=(size_t) (frame.right-frame.left); if (pixmap.bits_per_pixel <= 8) length&=0x7fff; if (pixmap.bits_per_pixel == 16) @@ -1044,7 +1059,7 @@ static Image *ReadPICTImage(const ImageInfo *image_info, break; } else - for (i=0; i < (int) height; i++) + for (i=0; i < (ssize_t) height; i++) { if (EOFBlob(image) != MagickFalse) break; @@ -1099,9 +1114,6 @@ static Image *ReadPICTImage(const ImageInfo *image_info, case 0x9a: case 0x9b: { - Image - *tile_image; - PICTRectangle source, destination; @@ -1123,7 +1135,7 @@ static Image *ReadPICTImage(const ImageInfo *image_info, */ bytes_per_line=0; if ((code != 0x9a) && (code != 0x9b)) - bytes_per_line=1L*ReadBlobMSBShort(image); + bytes_per_line=(ssize_t) ReadBlobMSBShort(image); else { (void) ReadBlobMSBShort(image); @@ -1131,24 +1143,20 @@ static Image *ReadPICTImage(const ImageInfo *image_info, (void) ReadBlobMSBShort(image); } if (ReadRectangle(image,&frame) == MagickFalse) - ThrowReaderException(CorruptImageError,"ImproperImageHeader"); + ThrowPICTException(CorruptImageError,"ImproperImageHeader"); /* Initialize tile image. */ - tile_image=CloneImage(image,1UL*(frame.right-frame.left), - 1UL*(frame.bottom-frame.top),MagickTrue,exception); + tile_image=CloneImage(image,(size_t) (frame.right-frame.left), + (size_t) (frame.bottom-frame.top),MagickTrue,exception); if (tile_image == (Image *) NULL) - ThrowReaderException(CorruptImageError,"ImproperImageHeader"); + ThrowPICTException(CorruptImageError,"ImproperImageHeader"); if ((code == 0x9a) || (code == 0x9b) || ((bytes_per_line & 0x8000) != 0)) { if (ReadPixmap(image,&pixmap) == MagickFalse) - { - tile_image=DestroyImage(tile_image); - ThrowReaderException(CorruptImageError, - "ImproperImageHeader"); - } - tile_image->depth=1UL*pixmap.component_size; + ThrowPICTException(CorruptImageError,"ImproperImageHeader"); + tile_image->depth=(size_t) pixmap.component_size; tile_image->alpha_trait=pixmap.component_count == 4 ? BlendPixelTrait : UndefinedPixelTrait; tile_image->resolution.x=(double) pixmap.horizontal_resolution; @@ -1166,17 +1174,14 @@ static Image *ReadPICTImage(const ImageInfo *image_info, if ((bytes_per_line & 0x8000) != 0) { (void) ReadBlobMSBLong(image); - flags=1L*ReadBlobMSBShort(image); + flags=(ssize_t) ReadBlobMSBShort(image); tile_image->colors=1UL*ReadBlobMSBShort(image)+1; } status=AcquireImageColormap(tile_image,tile_image->colors, exception); if (status == MagickFalse) - { - tile_image=DestroyImage(tile_image); - ThrowReaderException(ResourceLimitError, - "MemoryAllocationFailed"); - } + ThrowPICTException(ResourceLimitError, + "MemoryAllocationFailed"); if ((bytes_per_line & 0x8000) != 0) { for (i=0; i < (ssize_t) tile_image->colors; i++) @@ -1206,15 +1211,9 @@ static Image *ReadPICTImage(const ImageInfo *image_info, } } if (ReadRectangle(image,&source) == MagickFalse) - { - tile_image=DestroyImage(tile_image); - ThrowReaderException(CorruptImageError,"ImproperImageHeader"); - } + ThrowPICTException(CorruptImageError,"ImproperImageHeader"); if (ReadRectangle(image,&destination) == MagickFalse) - { - tile_image=DestroyImage(tile_image); - ThrowReaderException(CorruptImageError,"ImproperImageHeader"); - } + ThrowPICTException(CorruptImageError,"ImproperImageHeader"); (void) ReadBlobMSBShort(image); if ((code == 0x91) || (code == 0x99) || (code == 0x9b)) { @@ -1228,17 +1227,13 @@ static Image *ReadPICTImage(const ImageInfo *image_info, } if ((code != 0x9a) && (code != 0x9b) && (bytes_per_line & 0x8000) == 0) - pixels=DecodeImage(image,tile_image,1UL*bytes_per_line,1,&extent, - exception); + pixels=DecodeImage(image,tile_image,(size_t) bytes_per_line,1, + &extent,exception); else - pixels=DecodeImage(image,tile_image,1UL*bytes_per_line,1U* - pixmap.bits_per_pixel,&extent,exception); + pixels=DecodeImage(image,tile_image,(size_t) bytes_per_line, + (unsigned int) pixmap.bits_per_pixel,&extent,exception); if (pixels == (unsigned char *) NULL) - { - tile_image=DestroyImage(tile_image); - ThrowReaderException(ResourceLimitError, - "MemoryAllocationFailed"); - } + ThrowPICTException(ResourceLimitError,"MemoryAllocationFailed"); /* Convert PICT tile image to pixel packets. */ @@ -1246,10 +1241,7 @@ static Image *ReadPICTImage(const ImageInfo *image_info, for (y=0; y < (ssize_t) tile_image->rows; y++) { if (p > (pixels+extent+image->columns)) - { - tile_image=DestroyImage(tile_image); - ThrowReaderException(CorruptImageError,"NotEnoughPixelData"); - } + ThrowPICTException(CorruptImageError,"NotEnoughPixelData"); q=QueueAuthenticPixels(tile_image,0,y,tile_image->columns,1, exception); if (q == (Quantum *) NULL) @@ -1258,7 +1250,8 @@ static Image *ReadPICTImage(const ImageInfo *image_info, { if (tile_image->storage_class == PseudoClass) { - index=ConstrainColormapIndex(tile_image,*p,exception); + index=(Quantum) ConstrainColormapIndex(tile_image,(ssize_t) + *p,exception); SetPixelIndex(tile_image,index,q); SetPixelRed(tile_image, tile_image->colormap[(ssize_t) index].red,q); @@ -1271,8 +1264,8 @@ static Image *ReadPICTImage(const ImageInfo *image_info, { if (pixmap.bits_per_pixel == 16) { - i=(*p++); - j=(*p); + i=(ssize_t) (*p++); + j=(size_t) (*p); SetPixelRed(tile_image,ScaleCharToQuantum( (unsigned char) ((i & 0x7c) << 1)),q); SetPixelGreen(tile_image,ScaleCharToQuantum( @@ -1285,11 +1278,8 @@ static Image *ReadPICTImage(const ImageInfo *image_info, if (tile_image->alpha_trait == UndefinedPixelTrait) { if (p > (pixels+extent+2*image->columns)) - { - tile_image=DestroyImage(tile_image); - ThrowReaderException(CorruptImageError, - "NotEnoughPixelData"); - } + ThrowPICTException(CorruptImageError, + "NotEnoughPixelData"); SetPixelRed(tile_image,ScaleCharToQuantum(*p),q); SetPixelGreen(tile_image,ScaleCharToQuantum( *(p+tile_image->columns)),q); @@ -1299,11 +1289,8 @@ static Image *ReadPICTImage(const ImageInfo *image_info, else { if (p > (pixels+extent+3*image->columns)) - { - tile_image=DestroyImage(tile_image); - ThrowReaderException(CorruptImageError, - "NotEnoughPixelData"); - } + ThrowPICTException(CorruptImageError, + "NotEnoughPixelData"); SetPixelAlpha(tile_image,ScaleCharToQuantum(*p),q); SetPixelRed(tile_image,ScaleCharToQuantum( *(p+tile_image->columns)),q); @@ -1325,7 +1312,8 @@ static Image *ReadPICTImage(const ImageInfo *image_info, if (p < pixels) break; } - status=SetImageProgress(image,LoadImageTag,y,tile_image->rows); + status=SetImageProgress(image,LoadImageTag,(MagickOffsetType) y, + tile_image->rows); if (status == MagickFalse) break; } @@ -1334,7 +1322,8 @@ static Image *ReadPICTImage(const ImageInfo *image_info, if ((code == 0x9a) || (code == 0x9b) || ((bytes_per_line & 0x8000) != 0)) (void) CompositeImage(image,tile_image,CopyCompositeOp, - MagickTrue,destination.left,destination.top,exception); + MagickTrue,(ssize_t) destination.left,(ssize_t) + destination.top,exception); tile_image=DestroyImage(tile_image); break; } @@ -1364,8 +1353,7 @@ static Image *ReadPICTImage(const ImageInfo *image_info, if (count != (ssize_t) length) { info=(unsigned char *) RelinquishMagickMemory(info); - ThrowReaderException(ResourceLimitError, - "UnableToReadImageData"); + ThrowPICTException(ResourceLimitError,"UnableToReadImageData"); } switch (type) { @@ -1378,7 +1366,7 @@ static Image *ReadPICTImage(const ImageInfo *image_info, if (status == MagickFalse) { info=(unsigned char *) RelinquishMagickMemory(info); - ThrowReaderException(ResourceLimitError, + ThrowPICTException(ResourceLimitError, "MemoryAllocationFailed"); } break; @@ -1391,7 +1379,7 @@ static Image *ReadPICTImage(const ImageInfo *image_info, if (status == MagickFalse) { info=(unsigned char *) RelinquishMagickMemory(info); - ThrowReaderException(ResourceLimitError, + ThrowPICTException(ResourceLimitError, "MemoryAllocationFailed"); } profile=DestroyStringInfo(profile); @@ -1438,12 +1426,6 @@ static Image *ReadPICTImage(const ImageInfo *image_info, FILE *file; - Image - *tile_image; - - ImageInfo - *read_info; - int unique_file; @@ -1478,7 +1460,7 @@ static Image *ReadPICTImage(const ImageInfo *image_info, { (void) fclose(file); (void) RelinquishUniqueFileResource(read_info->filename); - ThrowReaderException(CorruptImageError,"ImproperImageHeader"); + ThrowPICTException(CorruptImageError,"ImproperImageHeader"); } for (i=0; i < 122; i++) if (ReadBlobByte(image) == EOF) @@ -1506,7 +1488,7 @@ static Image *ReadPICTImage(const ImageInfo *image_info, MagickMax(image->rows,tile_image->rows),exception); (void) TransformImageColorspace(image,tile_image->colorspace,exception); (void) CompositeImage(image,tile_image,CopyCompositeOp,MagickTrue, - frame.left,frame.right,exception); + (ssize_t) frame.left,(ssize_t) frame.right,exception); image->compression=tile_image->compression; tile_image=DestroyImage(tile_image); continue; @@ -1801,7 +1783,7 @@ static MagickBooleanType WritePICTImage(const ImageInfo *image_info, (void) WriteBlobMSBShort(image,PictVersion); (void) WriteBlobMSBShort(image,0x02ff); /* version #2 */ (void) WriteBlobMSBShort(image,PictInfoOp); - (void) WriteBlobMSBLong(image,0xFFFE0000UL); + (void) WriteBlobMSBLong(image,0xFFFE0000U); /* Write full size of the file, resolution, frame bounding box, and reserved. */ @@ -1832,13 +1814,13 @@ static MagickBooleanType WritePICTImage(const ImageInfo *image_info, (void) WriteBlobMSBShort(image,0xe0); (void) WriteBlobMSBShort(image,(unsigned short) (GetStringInfoLength(profile)+4)); - (void) WriteBlobMSBLong(image,0x00000000UL); + (void) WriteBlobMSBLong(image,0x00000000U); (void) WriteBlob(image,GetStringInfoLength(profile), GetStringInfoDatum(profile)); (void) WriteBlobMSBShort(image,0xa1); (void) WriteBlobMSBShort(image,0xe0); (void) WriteBlobMSBShort(image,4); - (void) WriteBlobMSBLong(image,0x00000002UL); + (void) WriteBlobMSBLong(image,0x00000002U); } /* Write crop region opcode and crop bounding box. @@ -1881,50 +1863,50 @@ static MagickBooleanType WritePICTImage(const ImageInfo *image_info, (void) WriteBlobMSBShort(image,PictJPEGOp); (void) WriteBlobMSBLong(image,(unsigned int) length+154); (void) WriteBlobMSBShort(image,0x0000); - (void) WriteBlobMSBLong(image,0x00010000UL); - (void) WriteBlobMSBLong(image,0x00000000UL); - (void) WriteBlobMSBLong(image,0x00000000UL); - (void) WriteBlobMSBLong(image,0x00000000UL); - (void) WriteBlobMSBLong(image,0x00010000UL); - (void) WriteBlobMSBLong(image,0x00000000UL); - (void) WriteBlobMSBLong(image,0x00000000UL); - (void) WriteBlobMSBLong(image,0x00000000UL); - (void) WriteBlobMSBLong(image,0x40000000UL); - (void) WriteBlobMSBLong(image,0x00000000UL); - (void) WriteBlobMSBLong(image,0x00000000UL); - (void) WriteBlobMSBLong(image,0x00000000UL); - (void) WriteBlobMSBLong(image,0x00400000UL); + (void) WriteBlobMSBLong(image,0x00010000U); + (void) WriteBlobMSBLong(image,0x00000000U); + (void) WriteBlobMSBLong(image,0x00000000U); + (void) WriteBlobMSBLong(image,0x00000000U); + (void) WriteBlobMSBLong(image,0x00010000U); + (void) WriteBlobMSBLong(image,0x00000000U); + (void) WriteBlobMSBLong(image,0x00000000U); + (void) WriteBlobMSBLong(image,0x00000000U); + (void) WriteBlobMSBLong(image,0x40000000U); + (void) WriteBlobMSBLong(image,0x00000000U); + (void) WriteBlobMSBLong(image,0x00000000U); + (void) WriteBlobMSBLong(image,0x00000000U); + (void) WriteBlobMSBLong(image,0x00400000U); (void) WriteBlobMSBShort(image,0x0000); (void) WriteBlobMSBShort(image,(unsigned short) image->rows); (void) WriteBlobMSBShort(image,(unsigned short) image->columns); (void) WriteBlobMSBShort(image,0x0000); (void) WriteBlobMSBShort(image,768); (void) WriteBlobMSBShort(image,0x0000); - (void) WriteBlobMSBLong(image,0x00000000UL); - (void) WriteBlobMSBLong(image,0x00566A70UL); - (void) WriteBlobMSBLong(image,0x65670000UL); - (void) WriteBlobMSBLong(image,0x00000000UL); - (void) WriteBlobMSBLong(image,0x00000001UL); - (void) WriteBlobMSBLong(image,0x00016170UL); - (void) WriteBlobMSBLong(image,0x706C0000UL); - (void) WriteBlobMSBLong(image,0x00000000UL); + (void) WriteBlobMSBLong(image,0x00000000U); + (void) WriteBlobMSBLong(image,0x00566A70U); + (void) WriteBlobMSBLong(image,0x65670000U); + (void) WriteBlobMSBLong(image,0x00000000U); + (void) WriteBlobMSBLong(image,0x00000001U); + (void) WriteBlobMSBLong(image,0x00016170U); + (void) WriteBlobMSBLong(image,0x706C0000U); + (void) WriteBlobMSBLong(image,0x00000000U); (void) WriteBlobMSBShort(image,768); (void) WriteBlobMSBShort(image,(unsigned short) image->columns); (void) WriteBlobMSBShort(image,(unsigned short) image->rows); (void) WriteBlobMSBShort(image,(unsigned short) x_resolution); (void) WriteBlobMSBShort(image,0x0000); (void) WriteBlobMSBShort(image,(unsigned short) y_resolution); - (void) WriteBlobMSBLong(image,0x00000000UL); - (void) WriteBlobMSBLong(image,0x87AC0001UL); - (void) WriteBlobMSBLong(image,0x0B466F74UL); - (void) WriteBlobMSBLong(image,0x6F202D20UL); - (void) WriteBlobMSBLong(image,0x4A504547UL); - (void) WriteBlobMSBLong(image,0x00000000UL); - (void) WriteBlobMSBLong(image,0x00000000UL); - (void) WriteBlobMSBLong(image,0x00000000UL); - (void) WriteBlobMSBLong(image,0x00000000UL); - (void) WriteBlobMSBLong(image,0x00000000UL); - (void) WriteBlobMSBLong(image,0x0018FFFFUL); + (void) WriteBlobMSBLong(image,0x00000000U); + (void) WriteBlobMSBLong(image,0x87AC0001U); + (void) WriteBlobMSBLong(image,0x0B466F74U); + (void) WriteBlobMSBLong(image,0x6F202D20U); + (void) WriteBlobMSBLong(image,0x4A504547U); + (void) WriteBlobMSBLong(image,0x00000000U); + (void) WriteBlobMSBLong(image,0x00000000U); + (void) WriteBlobMSBLong(image,0x00000000U); + (void) WriteBlobMSBLong(image,0x00000000U); + (void) WriteBlobMSBLong(image,0x00000000U); + (void) WriteBlobMSBLong(image,0x0018FFFFU); (void) WriteBlob(image,length,blob); if ((length & 0x01) != 0) (void) WriteBlobByte(image,'\0'); @@ -1938,7 +1920,7 @@ static MagickBooleanType WritePICTImage(const ImageInfo *image_info, else { (void) WriteBlobMSBShort(image,PictPixmapOp); - (void) WriteBlobMSBLong(image,(size_t) base_address); + (void) WriteBlobMSBLong(image,(unsigned int) base_address); } (void) WriteBlobMSBShort(image,(unsigned short) (row_bytes | 0x8000)); (void) WriteBlobMSBShort(image,(unsigned short) bounds.top); -- 2.49.0