% %
% %
% %
-+ 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 %
% %
% %
*/
static Image *ReadEPTImage(const ImageInfo *image_info,ExceptionInfo *exception)
{
+ const void
+ *postscript_data,
+ *tiff_data;
+
EPTInfo
ept_info;
MagickOffsetType
offset;
+ ssize_t
+ count;
+
/*
Open image file.
*/
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)
{
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