]> granicus.if.org Git - imagemagick/commitdiff
...
authorCristy <urban-warrior@imagemagick.org>
Sat, 19 Oct 2019 22:22:21 +0000 (18:22 -0400)
committerCristy <urban-warrior@imagemagick.org>
Sat, 19 Oct 2019 22:22:21 +0000 (18:22 -0400)
MagickCore/blob-private.h
MagickCore/blob.c
coders/ept.c

index 1fc60fda7907b72257846bed511790b200ec0209..45af72e10e7e0e453891573ce40d8c4bfd9a329a 100644 (file)
@@ -141,9 +141,7 @@ extern MagickExport void
   GetBlobInfo(BlobInfo *),
   *MapBlob(int,const MapMode,const MagickOffsetType,const size_t),
   MSBOrderLong(unsigned char *,const size_t),
-  MSBOrderShort(unsigned char *,const size_t),
-  *ReadBlobZC(Image *,const size_t),
-  *RelinquishBlobZC(Image *,void *);
+  MSBOrderShort(unsigned char *,const size_t);
 
 #if defined(__cplusplus) || defined(c_plusplus)
 }
index beb8a347ef3d2c4147798e0d860c6ae3280af9d6..829c99b3e547856ed52873208fa40267aa39aab9 100644 (file)
@@ -4805,86 +4805,6 @@ MagickExport char *ReadBlobString(Image *image,char *string)
 %                                                                             %
 %                                                                             %
 %                                                                             %
-+  R e a d B l o b Z C                                                        %
-%                                                                             %
-%                                                                             %
-%                                                                             %
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%
-% ReadBlobZC() reads data from the blob or image file and returns a pointer
-% to a buffer that contains the data.  If the image is in-memory, the in-memory
-% buffer is returned (zero copy), otherwise a buffer is allocated and the image
-% data is copied to it and returned.  NULL is returnedif the specified length
-% is zero, exceeds the confines of the image data, or if the buffer cannot be
-% allocated.  You must call RelinquishBlobZC() to free any allocated resources.
-%
-%  The format of the ReadBlobZC method is:
-%
-%      void *ReadBlobZC(Image *image,const size_t length)
-%
-%  A description of each parameter follows:
-%
-%    o image: the image.
-%
-%    o length:  Specifies an integer representing the number of bytes to read
-%      from the image.
-%
-*/
-
-MagickExport void *RelinquishBlobZC(Image *image,void *data)
-{
-  BlobInfo
-    *magick_restrict blob_info;
-
-  blob_info=image->blob;
-  if (blob_info->type != BlobStream)
-    return(RelinquishMagickMemory(data));
-  return((void *) NULL);
-}
-
-MagickExport void *ReadBlobZC(Image *image,const size_t length)
-{
-  BlobInfo
-    *magick_restrict blob_info;
-
-  ssize_t
-    count;
-
-  void
-    *data;
-
-  assert(image != (Image *) NULL);
-  assert(image->signature == MagickCoreSignature);
-  assert(image->blob != (BlobInfo *) NULL);
-  assert(image->blob->type != UndefinedStream);
-  if (length == 0)
-    return((void *) NULL);
-  blob_info=image->blob;
-  if (blob_info->type == BlobStream)
-    {
-      if ((blob_info->offset+length) >= (MagickOffsetType) blob_info->length)
-        {
-          blob_info->eof=MagickTrue;
-          return((void *) NULL);
-        }
-      data=blob_info->data+blob_info->offset;
-      blob_info->offset+=length;
-      return(data);
-    }
-  data=AcquireMagickMemory(length);
-  if (data == (void *) NULL)
-    return((void *) NULL);
-  count=ReadBlob(image,length,data);
-  if (count != (ssize_t) length)
-    data=RelinquishMagickMemory(data);
-  return(data);
-}
-\f
-/*
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%                                                                             %
-%                                                                             %
-%                                                                             %
 +   R e f e r e n c e B l o b                                                 %
 %                                                                             %
 %                                                                             %
index 4c1402d096d967eed71f10c9d67a0c9f4d17c559..21d3c24848dd2562b0575ef705ff03a314a89fdc 100644 (file)
@@ -156,6 +156,10 @@ static MagickBooleanType IsEPT(const unsigned char *magick,const size_t length)
 */
 static Image *ReadEPTImage(const ImageInfo *image_info,ExceptionInfo *exception)
 {
+  const void
+    *postscript_data,
+    *tiff_data;
+
   EPTInfo
     ept_info;
 
@@ -171,6 +175,9 @@ static Image *ReadEPTImage(const ImageInfo *image_info,ExceptionInfo *exception)
   MagickOffsetType
     offset;
 
+  ssize_t
+    count;
+
   /*
     Open image file.
   */
@@ -201,34 +208,61 @@ static Image *ReadEPTImage(const ImageInfo *image_info,ExceptionInfo *exception)
   ept_info.tiff_length=ReadBlobLSBLong(image);
   if ((MagickSizeType) ept_info.tiff_length > GetBlobSize(image))
     ThrowReaderException(CorruptImageError,"InsufficientImageDataInFile");
-  ept_info.tiff=NULL;
   (void) ReadBlobLSBShort(image);
+  ept_info.postscript=(unsigned char *) AcquireQuantumMemory(
+    GetBlobStreamData(image) == NULL ? ept_info.postscript_length+1 : 1,
+    sizeof(*ept_info.postscript));
+  if (ept_info.postscript == (unsigned char *) NULL)
+    ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
+  (void) memset(ept_info.postscript,0,(ept_info.postscript_length+1)*
+    sizeof(*ept_info.postscript));
+  ept_info.tiff=(unsigned char *) AcquireQuantumMemory(
+    GetBlobStreamData(image) == NULL ? ept_info.tiff_length+1 : 1,
+    sizeof(*ept_info.tiff));
+  if (ept_info.tiff == (unsigned char *) NULL)
+    {
+      ept_info.postscript=(unsigned char *) RelinquishMagickMemory(
+        ept_info.postscript);
+      ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
+    }
+  (void) memset(ept_info.tiff,0,(ept_info.tiff_length+1)*
+    sizeof(*ept_info.tiff));
+  offset=SeekBlob(image,ept_info.tiff_offset,SEEK_SET);
+  if ((ept_info.tiff_length != 0) && (offset < 30))
+    {
+      ept_info.tiff=(unsigned char *) RelinquishMagickMemory(ept_info.tiff);
+      ept_info.postscript=(unsigned char *) RelinquishMagickMemory(
+        ept_info.postscript);
+      ThrowReaderException(CorruptImageError,"ImproperImageHeader");
+    }
+  tiff_data=ReadBlobStream(image,ept_info.tiff_length,ept_info.tiff,&count);
+  if (count != (ssize_t) (ept_info.tiff_length))
+    (void) ThrowMagickException(exception,GetMagickModule(),CorruptImageWarning,
+      "InsufficientImageDataInFile","`%s'",image->filename);
   offset=SeekBlob(image,ept_info.postscript_offset,SEEK_SET);
   if ((ept_info.postscript_length != 0) && (offset < 30))
-    ThrowReaderException(CorruptImageError,"ImproperImageHeader");
-  ept_info.postscript=ReadBlobZC(image,ept_info.postscript_length);
-  if ((ept_info.postscript == NULL) && (ept_info.tiff_length != 0))
     {
-      offset=SeekBlob(image,ept_info.tiff_offset,SEEK_SET);
-      if (offset >= 30)
-        ept_info.tiff=ReadBlobZC(image,ept_info.tiff_length);
+      ept_info.tiff=(unsigned char *) RelinquishMagickMemory(ept_info.tiff);
+      ept_info.postscript=(unsigned char *) RelinquishMagickMemory(
+        ept_info.postscript);
+      ThrowReaderException(CorruptImageError,"ImproperImageHeader");
     }
+  postscript_data=ReadBlobStream(image,ept_info.postscript_length,
+    ept_info.postscript,&count);
+  if (count != (ssize_t) (ept_info.postscript_length))
+    (void) ThrowMagickException(exception,GetMagickModule(),CorruptImageWarning,
+      "InsufficientImageDataInFile","`%s'",image->filename);
   (void) CloseBlob(image);
   image=DestroyImage(image);
   read_info=CloneImageInfo(image_info);
-  if (ept_info.postscript != NULL)
-     {
-       (void) CopyMagickString(read_info->magick,"EPS",MagickPathExtent);
-       image=BlobToImage(read_info,ept_info.postscript,
-         ept_info.postscript_length,exception);
-     }
-  else
-    if (ept_info.tiff != NULL)
-      {
-        (void) CopyMagickString(read_info->magick,"TIFF",MagickPathExtent);
-        image=BlobToImage(read_info,ept_info.tiff,ept_info.tiff_length,
-          exception);
-      }
+  (void) CopyMagickString(read_info->magick,"EPS",MagickPathExtent);
+  image=BlobToImage(read_info,postscript_data,ept_info.postscript_length,
+    exception);
+  if (image == (Image *) NULL)
+    {
+      (void) CopyMagickString(read_info->magick,"TIFF",MagickPathExtent);
+      image=BlobToImage(read_info,tiff_data,ept_info.tiff_length,exception);
+    }
   read_info=DestroyImageInfo(read_info);
   if (image != (Image *) NULL)
     {
@@ -236,10 +270,9 @@ static Image *ReadEPTImage(const ImageInfo *image_info,ExceptionInfo *exception)
         MagickPathExtent);
       (void) CopyMagickString(image->magick,"EPT",MagickPathExtent);
     }
-  if (ept_info.tiff != NULL)
-    ept_info.tiff=RelinquishBlobZC(image,ept_info.tiff);
-  if (ept_info.postscript != NULL)
-    ept_info.postscript=RelinquishBlobZC(image,ept_info.postscript);
+  ept_info.tiff=(unsigned char *) RelinquishMagickMemory(ept_info.tiff);
+  ept_info.postscript=(unsigned char *) RelinquishMagickMemory(
+    ept_info.postscript);
   return(image);
 }
 \f