From 05249ee441d936003941affe4bfb72c11bacb5b5 Mon Sep 17 00:00:00 2001 From: Dirk Lemstra Date: Thu, 18 Jul 2019 22:43:47 +0200 Subject: [PATCH] Only read the version once. --- coders/ps.c | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/coders/ps.c b/coders/ps.c index 8fbf1b20b..1b937aaf7 100644 --- a/coders/ps.c +++ b/coders/ps.c @@ -221,8 +221,8 @@ static void ReadPSInfo(const ImageInfo *image_info,Image *image, #define ICCProfile "BeginICCProfile:" #define PhotoshopProfile "BeginPhotoshop:" - MagickByteBuffer - buffer; + char + version[128]; int c; @@ -230,6 +230,9 @@ static void ReadPSInfo(const ImageInfo *image_info,Image *image, MagickBooleanType skip; + MagickByteBuffer + buffer; + register char *p; @@ -285,6 +288,7 @@ static void ReadPSInfo(const ImageInfo *image_info,Image *image, hex_digits[(int) 'F']=15; extent=0; priority=0; + *version='\0'; spotcolor=0; skip=MagickFalse; (void) memset(&buffer,0,sizeof(buffer)); @@ -314,10 +318,17 @@ static void ReadPSInfo(const ImageInfo *image_info,Image *image, skip=MagickFalse; if (skip != MagickFalse) continue; - if (CompareMagickByteBuffer(&buffer,PostscriptLevel,strlen(PostscriptLevel)) != MagickFalse) + if ((*version == '\0') && + (CompareMagickByteBuffer(&buffer,PostscriptLevel,strlen(PostscriptLevel)) != MagickFalse)) { - p=GetMagickByteBufferDatum(&buffer)+4; - (void) SetImageProperty(image,"ps:Level",p,exception); + i=0; + for (c=ReadMagickByteBuffer(&buffer); c != EOF; c=ReadMagickByteBuffer(&buffer)) + { + if ((c == '\r') || (c == '\n') || ((i+1) == sizeof(version))) + break; + version[i++]=(char) c; + } + version[i]='\0'; } if (CompareMagickByteBuffer(&buffer,ImageData,strlen(ImageData)) != MagickFalse) { @@ -475,6 +486,8 @@ static void ReadPSInfo(const ImageInfo *image_info,Image *image, ps_info->bounds=bounds; priority=i; } + if (version[0] != '\0') + (void) SetImageProperty(image,"ps:Level",version,exception); } static inline void CleanupPSInfo(PSInfo *pdf_info) -- 2.40.0