From: Cristy Date: Sat, 6 Jul 2019 12:47:43 +0000 (-0400) Subject: ... X-Git-Tag: 7.0.8-54~86 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=ede7fb2f230f9c999227cfe59e5c2ef80c5daf9d;p=imagemagick ... --- diff --git a/coders/pdf.c b/coders/pdf.c index e42ed408b..3fa74e532 100644 --- a/coders/pdf.c +++ b/coders/pdf.c @@ -109,7 +109,6 @@ typedef struct _PDFInfo StringInfo *profile; - } PDFInfo; typedef struct _PDFBuffer @@ -117,14 +116,12 @@ typedef struct _PDFBuffer Image *image; - size_t - offset; - ssize_t + offset, count; unsigned char - data[MagickPathExtent]; + data[8192]; } PDFBuffer; /* @@ -409,9 +406,9 @@ static MagickBooleanType IsPDFRendered(const char *path) static inline int ReadPDFByte(PDFBuffer *buffer) { - if (((ssize_t)buffer->offset == buffer->count) && (buffer->offset > 0)) + if ((buffer->offset == buffer->count) && (buffer->offset > 0)) { - if (buffer->count != sizeof(buffer->data)) + if (buffer->count != (ssize_t) sizeof(buffer->data)) return(EOF); buffer->offset=0; } @@ -430,10 +427,9 @@ static char *MovePDFBuffer(PDFBuffer *buffer) i; i=1; /* Skip first to avoid reload of buffer; */ - while ((ssize_t)buffer->offset < buffer->count) + while (buffer->offset < buffer->count) buffer->data[i++]=buffer->data[buffer->offset++]; - buffer->count=ReadBlob(buffer->image,sizeof(buffer->data)-i, - buffer->data+i); + buffer->count=ReadBlob(buffer->image,sizeof(buffer->data)-i,buffer->data+i); buffer->count+=i; buffer->offset=1; return((char *) buffer->data+1); @@ -441,14 +437,14 @@ static char *MovePDFBuffer(PDFBuffer *buffer) static inline void CheckRemainingPDFBuffer(PDFBuffer *buffer,size_t length) { - if (buffer->offset+length > sizeof(buffer->data)) + if ((buffer->offset+length) > (ssize_t) sizeof(buffer->data)) (void) MovePDFBuffer(buffer); } static inline void SkipPDFBytes(PDFBuffer *buffer,size_t count) { CheckRemainingPDFBuffer(buffer,count); - if (buffer->offset+count < buffer->count) + if ((buffer->offset+count) < buffer->count) buffer->offset+=count; } @@ -480,7 +476,9 @@ static void ReadPDFXMPProfile(PDFInfo *pdf_info,PDFBuffer *buffer) *p; size_t - length, + length; + + ssize_t count; if (pdf_info->profile != (StringInfo *) NULL) @@ -495,7 +493,7 @@ static void ReadPDFXMPProfile(PDFInfo *pdf_info,PDFBuffer *buffer) count=1; for (c=ReadPDFByte(buffer); c != EOF; c=ReadPDFByte(buffer)) { - if (count == length) + if (count == (ssize_t) length) { length+=MagickPathExtent; SetStringInfoLength(pdf_info->profile,length); @@ -507,15 +505,15 @@ static void ReadPDFXMPProfile(PDFInfo *pdf_info,PDFBuffer *buffer) found_end=ComparePDFBuffer(EndXMPPacket,buffer,strlen(EndXMPPacket)); else { - if (c == (int)'>') + if (c == (int) '>') break; } } - SetStringInfoLength(pdf_info->profile,count); + SetStringInfoLength(pdf_info->profile,(size_t) count); } -static void ReadPDFInfo(const ImageInfo *image_info,Image *image,PDFInfo *pdf_info, - ExceptionInfo *exception) +static void ReadPDFInfo(const ImageInfo *image_info,Image *image, + PDFInfo *pdf_info,ExceptionInfo *exception) { #define CMYKProcessColor "CMYKProcessColor" #define CropBox "CropBox" @@ -553,11 +551,11 @@ static void ReadPDFInfo(const ImageInfo *image_info,Image *image,PDFInfo *pdf_in (void) memset(&bounds,0,sizeof(bounds)); (void) memset(pdf_info,0,sizeof(*pdf_info)); - pdf_info->cmyk=image_info->colorspace == CMYKColorspace ? MagickTrue : MagickFalse; + pdf_info->cmyk=image_info->colorspace == CMYKColorspace ? MagickTrue : + MagickFalse; pdf_info->cropbox=IsStringTrue(GetImageOption(image_info,"pdf:use-cropbox")); pdf_info->trimbox=IsStringTrue(GetImageOption(image_info,"pdf:use-trimbox")); - - version[0]='\0'; + *version='\0'; spotcolor=0; (void) memset(&buffer,0,sizeof(buffer)); buffer.image=image; @@ -566,7 +564,8 @@ static void ReadPDFInfo(const ImageInfo *image_info,Image *image,PDFInfo *pdf_in switch(c) { case '%': - if (version[0] == '\0') + { + if (*version == '\0') { i=0; for (c=ReadPDFByte(&buffer); c != EOF; c=ReadPDFByte(&buffer)) @@ -578,9 +577,12 @@ static void ReadPDFInfo(const ImageInfo *image_info,Image *image,PDFInfo *pdf_in version[i]='\0'; } continue; + } case '<': + { ReadPDFXMPProfile(pdf_info,&buffer); continue; + } case '/': break; default: @@ -640,11 +642,11 @@ static void ReadPDFInfo(const ImageInfo *image_info,Image *image,PDFInfo *pdf_in Note region defined by crop box. */ p=MovePDFBuffer(&buffer); - count=(ssize_t) sscanf(p,"CropBox [%lf %lf %lf %lf", - &bounds.x1,&bounds.y1,&bounds.x2,&bounds.y2); + count=(ssize_t) sscanf(p,"CropBox [%lf %lf %lf %lf",&bounds.x1, + &bounds.y1,&bounds.x2,&bounds.y2); if (count != 4) - count=(ssize_t) sscanf(p,"CropBox[%lf %lf %lf %lf", - &bounds.x1,&bounds.y1,&bounds.x2,&bounds.y2); + count=(ssize_t) sscanf(p,"CropBox[%lf %lf %lf %lf",&bounds.x1, + &bounds.y1,&bounds.x2,&bounds.y2); } } else @@ -656,11 +658,11 @@ static void ReadPDFInfo(const ImageInfo *image_info,Image *image,PDFInfo *pdf_in Note region defined by trim box. */ p=MovePDFBuffer(&buffer); - count=(ssize_t) sscanf(p,"TrimBox [%lf %lf %lf %lf", - &bounds.x1,&bounds.y1,&bounds.x2,&bounds.y2); + count=(ssize_t) sscanf(p,"TrimBox [%lf %lf %lf %lf",&bounds.x1, + &bounds.y1,&bounds.x2,&bounds.y2); if (count != 4) - count=(ssize_t) sscanf(p,"TrimBox[%lf %lf %lf %lf", - &bounds.x1,&bounds.y1,&bounds.x2,&bounds.y2); + count=(ssize_t) sscanf(p,"TrimBox[%lf %lf %lf %lf",&bounds.x1, + &bounds.y1,&bounds.x2,&bounds.y2); } } else @@ -670,11 +672,11 @@ static void ReadPDFInfo(const ImageInfo *image_info,Image *image,PDFInfo *pdf_in Note region defined by media box. */ p=MovePDFBuffer(&buffer); - count=(ssize_t) sscanf(p,"MediaBox [%lf %lf %lf %lf", - &bounds.x1,&bounds.y1,&bounds.x2,&bounds.y2); + count=(ssize_t) sscanf(p,"MediaBox [%lf %lf %lf %lf",&bounds.x1, + &bounds.y1,&bounds.x2,&bounds.y2); if (count != 4) - count=(ssize_t) sscanf(p,"MediaBox[%lf %lf %lf %lf", - &bounds.x1,&bounds.y1,&bounds.x2,&bounds.y2); + count=(ssize_t) sscanf(p,"MediaBox[%lf %lf %lf %lf",&bounds.x1, + &bounds.y1,&bounds.x2,&bounds.y2); } if (count != 4) continue; @@ -841,10 +843,10 @@ static Image *ReadPDFImage(const ImageInfo *image_info,ExceptionInfo *exception) image=DestroyImage(image); return((Image *) NULL); } - page.width=(size_t) ceil((double) (page.width*image->resolution.x/delta.x) - -0.5); + page.width=(size_t) ceil((double) (page.width*image->resolution.x/ + delta.x)-0.5); page.height=(size_t) ceil((double) (page.height*image->resolution.y/ - delta.y) -0.5); + delta.y)-0.5); fitPage=MagickTrue; } if ((fabs(pdf_info.angle) == 90.0) || (fabs(pdf_info.angle) == 270.0))