From: Cristy Date: Sat, 28 Oct 2017 01:47:57 +0000 (-0400) Subject: ... X-Git-Tag: 7.0.7-9~16 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=bf6a1307f0df39f00a591a733bee3c41ba3b02e0;p=imagemagick ... --- diff --git a/MagickCore/blob.c b/MagickCore/blob.c index 5b7ab6194..196089433 100644 --- a/MagickCore/blob.c +++ b/MagickCore/blob.c @@ -587,6 +587,9 @@ MagickExport BlobInfo *CloneBlobInfo(const BlobInfo *blob_info) */ MagickExport MagickBooleanType CloseBlob(Image *image) { + BlobInfo + *restrict blob_info; + int status; @@ -598,10 +601,11 @@ MagickExport MagickBooleanType CloseBlob(Image *image) if (image->debug != MagickFalse) (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); assert(image->blob != (BlobInfo *) NULL); - if (image->blob->type == UndefinedStream) + blob_info=image->blob; + if (blob_info->type == UndefinedStream) return(MagickTrue); status=SyncBlob(image); - switch (image->blob->type) + switch (blob_info->type) { case UndefinedStream: case StandardStream: @@ -609,22 +613,22 @@ MagickExport MagickBooleanType CloseBlob(Image *image) case FileStream: case PipeStream: { - if (image->blob->synchronize != MagickFalse) - status=fsync(fileno(image->blob->file_info.file)); - status=ferror(image->blob->file_info.file); + if (blob_info->synchronize != MagickFalse) + status=fsync(fileno(blob_info->file_info.file)); + status=ferror(blob_info->file_info.file); break; } case ZipStream: { #if defined(MAGICKCORE_ZLIB_DELEGATE) - (void) gzerror(image->blob->file_info.gzfile,&status); + (void) gzerror(blob_info->file_info.gzfile,&status); #endif break; } case BZipStream: { #if defined(MAGICKCORE_BZLIB_DELEGATE) - (void) BZ2_bzerror(image->blob->file_info.bzfile,&status); + (void) BZ2_bzerror(blob_info->file_info.bzfile,&status); #endif break; } @@ -632,54 +636,54 @@ MagickExport MagickBooleanType CloseBlob(Image *image) break; case BlobStream: { - if ((image->blob->file_info.file != (FILE *) NULL) && - (image->blob->synchronize != MagickFalse)) + if ((blob_info->file_info.file != (FILE *) NULL) && + (blob_info->synchronize != MagickFalse)) { - (void) fsync(fileno(image->blob->file_info.file)); - status=ferror(image->blob->file_info.file); + (void) fsync(fileno(blob_info->file_info.file)); + status=ferror(blob_info->file_info.file); } break; } case CustomStream: break; } - image->blob->status=status < 0 ? MagickTrue : MagickFalse; - image->blob->size=GetBlobSize(image); - image->extent=image->blob->size; - image->blob->eof=MagickFalse; - if (image->blob->exempt != MagickFalse) + blob_info->status=status < 0 ? MagickTrue : MagickFalse; + blob_info->size=GetBlobSize(image); + image->extent=blob_info->size; + blob_info->eof=MagickFalse; + if (blob_info->exempt != MagickFalse) { - image->blob->type=UndefinedStream; - return(image->blob->status); + blob_info->type=UndefinedStream; + return(blob_info->status); } - switch (image->blob->type) + switch (blob_info->type) { case UndefinedStream: case StandardStream: break; case FileStream: { - status=fclose(image->blob->file_info.file); + status=fclose(blob_info->file_info.file); break; } case PipeStream: { #if defined(MAGICKCORE_HAVE_PCLOSE) - status=pclose(image->blob->file_info.file); + status=pclose(blob_info->file_info.file); #endif break; } case ZipStream: { #if defined(MAGICKCORE_ZLIB_DELEGATE) - status=gzclose(image->blob->file_info.gzfile); + status=gzclose(blob_info->file_info.gzfile); #endif break; } case BZipStream: { #if defined(MAGICKCORE_BZLIB_DELEGATE) - BZ2_bzclose(image->blob->file_info.bzfile); + BZ2_bzclose(blob_info->file_info.bzfile); #endif break; } @@ -687,16 +691,16 @@ MagickExport MagickBooleanType CloseBlob(Image *image) break; case BlobStream: { - if (image->blob->file_info.file != (FILE *) NULL) - status=fclose(image->blob->file_info.file); + if (blob_info->file_info.file != (FILE *) NULL) + status=fclose(blob_info->file_info.file); break; } case CustomStream: break; } - (void) DetachBlob(image->blob); - image->blob->status=status < 0 ? MagickTrue : MagickFalse; - return(image->blob->status); + (void) DetachBlob(blob_info); + blob_info->status=status < 0 ? MagickTrue : MagickFalse; + return(blob_info->status); } /* @@ -877,6 +881,9 @@ MagickExport Image *CustomStreamToImage(const ImageInfo *image_info, */ MagickExport void DestroyBlob(Image *image) { + BlobInfo + *restrict blob_info; + MagickBooleanType destroy; @@ -886,25 +893,26 @@ MagickExport void DestroyBlob(Image *image) (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); assert(image->blob != (BlobInfo *) NULL); assert(image->blob->signature == MagickCoreSignature); + blob_info=image->blob; destroy=MagickFalse; - LockSemaphoreInfo(image->blob->semaphore); - image->blob->reference_count--; - assert(image->blob->reference_count >= 0); - if (image->blob->reference_count == 0) + LockSemaphoreInfo(blob_info->semaphore); + blob_info->reference_count--; + assert(blob_info->reference_count >= 0); + if (blob_info->reference_count == 0) destroy=MagickTrue; - UnlockSemaphoreInfo(image->blob->semaphore); + UnlockSemaphoreInfo(blob_info->semaphore); if (destroy == MagickFalse) return; (void) CloseBlob(image); - if (image->blob->mapped != MagickFalse) + if (blob_info->mapped != MagickFalse) { - (void) UnmapBlob(image->blob->data,image->blob->length); - RelinquishMagickResource(MapResource,image->blob->length); + (void) UnmapBlob(blob_info->data,blob_info->length); + RelinquishMagickResource(MapResource,blob_info->length); } - if (image->blob->semaphore != (SemaphoreInfo *) NULL) - RelinquishSemaphoreInfo(&image->blob->semaphore); - image->blob->signature=(~MagickCoreSignature); - image->blob=(BlobInfo *) RelinquishMagickMemory(image->blob); + if (blob_info->semaphore != (SemaphoreInfo *) NULL) + RelinquishSemaphoreInfo(&blob_info->semaphore); + blob_info->signature=(~MagickCoreSignature); + image->blob=(BlobInfo *) RelinquishMagickMemory(blob_info); } /* @@ -1018,7 +1026,8 @@ MagickExport void *DetachBlob(BlobInfo *blob_info) MagickExport void DisassociateBlob(Image *image) { BlobInfo - *blob; + *restrict blob_info, + *clone_info; MagickBooleanType clone; @@ -1029,17 +1038,18 @@ MagickExport void DisassociateBlob(Image *image) (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); assert(image->blob != (BlobInfo *) NULL); assert(image->blob->signature == MagickCoreSignature); + blob_info=image->blob; clone=MagickFalse; - LockSemaphoreInfo(image->blob->semaphore); - assert(image->blob->reference_count >= 0); - if (image->blob->reference_count > 1) + LockSemaphoreInfo(blob_info->semaphore); + assert(blob_info->reference_count >= 0); + if (blob_info->reference_count > 1) clone=MagickTrue; - UnlockSemaphoreInfo(image->blob->semaphore); + UnlockSemaphoreInfo(blob_info->semaphore); if (clone == MagickFalse) return; - blob=CloneBlobInfo(image->blob); + clone_info=CloneBlobInfo(blob_info); DestroyBlob(image); - image->blob=blob; + image->blob=clone_info; } /* @@ -1162,13 +1172,17 @@ MagickExport void DuplicateBlob(Image *image,const Image *duplicate) */ MagickExport int EOFBlob(const Image *image) { + BlobInfo + *restrict blob_info; + assert(image != (Image *) NULL); assert(image->signature == MagickCoreSignature); if (image->debug != MagickFalse) (void) LogMagickEvent(TraceEvent,GetMagickModule(),"..."); assert(image->blob != (BlobInfo *) NULL); assert(image->blob->type != UndefinedStream); - switch (image->blob->type) + blob_info=image->blob; + switch (blob_info->type) { case UndefinedStream: case StandardStream: @@ -1176,13 +1190,13 @@ MagickExport int EOFBlob(const Image *image) case FileStream: case PipeStream: { - image->blob->eof=feof(image->blob->file_info.file) != 0 ? MagickTrue : + blob_info->eof=feof(blob_info->file_info.file) != 0 ? MagickTrue : MagickFalse; break; } case ZipStream: { - image->blob->eof=MagickFalse; + blob_info->eof=MagickFalse; break; } case BZipStream: @@ -1192,14 +1206,14 @@ MagickExport int EOFBlob(const Image *image) status; status=0; - (void) BZ2_bzerror(image->blob->file_info.bzfile,&status); - image->blob->eof=status == BZ_UNEXPECTED_EOF ? MagickTrue : MagickFalse; + (void) BZ2_bzerror(blob_info->file_info.bzfile,&status); + blob_info->eof=status == BZ_UNEXPECTED_EOF ? MagickTrue : MagickFalse; #endif break; } case FifoStream: { - image->blob->eof=MagickFalse; + blob_info->eof=MagickFalse; break; } case BlobStream: @@ -1207,7 +1221,7 @@ MagickExport int EOFBlob(const Image *image) case CustomStream: break; } - return((int) image->blob->eof); + return((int) blob_info->eof); } /* @@ -1663,6 +1677,9 @@ MagickExport const struct stat *GetBlobProperties(const Image *image) */ MagickExport MagickSizeType GetBlobSize(const Image *image) { + BlobInfo + *restrict blob_info; + MagickSizeType extent; @@ -1671,24 +1688,25 @@ MagickExport MagickSizeType GetBlobSize(const Image *image) if (image->debug != MagickFalse) (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); assert(image->blob != (BlobInfo *) NULL); + blob_info=image->blob; extent=0; - switch (image->blob->type) + switch (blob_info->type) { case UndefinedStream: case StandardStream: { - extent=image->blob->size; + extent=blob_info->size; break; } case FileStream: { - if (fstat(fileno(image->blob->file_info.file),&image->blob->properties) == 0) - extent=(MagickSizeType) image->blob->properties.st_size; + if (fstat(fileno(blob_info->file_info.file),&blob_info->properties) == 0) + extent=(MagickSizeType) blob_info->properties.st_size; break; } case PipeStream: { - extent=image->blob->size; + extent=blob_info->size; break; } case ZipStream: @@ -1697,32 +1715,32 @@ MagickExport MagickSizeType GetBlobSize(const Image *image) MagickBooleanType status; - status=GetPathAttributes(image->filename,&image->blob->properties); + status=GetPathAttributes(image->filename,&blob_info->properties); if (status != MagickFalse) - extent=(MagickSizeType) image->blob->properties.st_size; + extent=(MagickSizeType) blob_info->properties.st_size; break; } case FifoStream: break; case BlobStream: { - extent=(MagickSizeType) image->blob->length; + extent=(MagickSizeType) blob_info->length; break; } case CustomStream: { - if ((image->blob->custom_stream->teller != (CustomStreamTeller) NULL) && - (image->blob->custom_stream->seeker != (CustomStreamSeeker) NULL)) + if ((blob_info->custom_stream->teller != (CustomStreamTeller) NULL) && + (blob_info->custom_stream->seeker != (CustomStreamSeeker) NULL)) { MagickOffsetType offset; - offset=image->blob->custom_stream->teller( - image->blob->custom_stream->data); - extent=(MagickSizeType) image->blob->custom_stream->seeker(0,SEEK_END, - image->blob->custom_stream->data); - (void) image->blob->custom_stream->seeker(offset,SEEK_SET, - image->blob->custom_stream->data); + offset=blob_info->custom_stream->teller( + blob_info->custom_stream->data); + extent=(MagickSizeType) blob_info->custom_stream->seeker(0,SEEK_END, + blob_info->custom_stream->data); + (void) blob_info->custom_stream->seeker(offset,SEEK_SET, + blob_info->custom_stream->data); } break; } @@ -1960,7 +1978,7 @@ MagickExport void ImageToCustomStream(const ImageInfo *image_info,Image *image, *magick_info; ImageInfo - *blob_info; + *clone_info; MagickBooleanType status; @@ -1976,21 +1994,21 @@ MagickExport void ImageToCustomStream(const ImageInfo *image_info,Image *image, assert(image_info->custom_stream->signature == MagickCoreSignature); assert(image_info->custom_stream->writer != (CustomStreamHandler) NULL); assert(exception != (ExceptionInfo *) NULL); - blob_info=CloneImageInfo(image_info); - blob_info->adjoin=MagickFalse; - (void) SetImageInfo(blob_info,1,exception); - if (*blob_info->magick != '\0') - (void) CopyMagickString(image->magick,blob_info->magick,MagickPathExtent); + clone_info=CloneImageInfo(image_info); + clone_info->adjoin=MagickFalse; + (void) SetImageInfo(clone_info,1,exception); + if (*clone_info->magick != '\0') + (void) CopyMagickString(image->magick,clone_info->magick,MagickPathExtent); magick_info=GetMagickInfo(image->magick,exception); if (magick_info == (const MagickInfo *) NULL) { (void) ThrowMagickException(exception,GetMagickModule(), MissingDelegateError,"NoEncodeDelegateForThisImageFormat","`%s'", image->magick); - blob_info=DestroyImageInfo(blob_info); + clone_info=DestroyImageInfo(clone_info); return; } - (void) CopyMagickString(blob_info->magick,image->magick,MagickPathExtent); + (void) CopyMagickString(clone_info->magick,image->magick,MagickPathExtent); if (GetMagickBlobSupport(magick_info) != MagickFalse) { /* @@ -1998,7 +2016,7 @@ MagickExport void ImageToCustomStream(const ImageInfo *image_info,Image *image, */ (void) CloseBlob(image); *image->filename='\0'; - (void) WriteImage(blob_info,image,exception); + (void) WriteImage(clone_info,image,exception); (void) CloseBlob(image); } else @@ -2015,14 +2033,14 @@ MagickExport void ImageToCustomStream(const ImageInfo *image_info,Image *image, /* Write file to disk in blob image format. */ - blob_info->custom_stream=(CustomStreamInfo *) NULL; + clone_info->custom_stream=(CustomStreamInfo *) NULL; blob=(unsigned char *) AcquireQuantumMemory(MagickMaxBufferExtent, sizeof(*blob)); if (blob == (unsigned char *) NULL) { ThrowFileException(exception,BlobError,"UnableToWriteBlob", image_info->filename); - blob_info=DestroyImageInfo(blob_info); + clone_info=DestroyImageInfo(clone_info); return; } file=AcquireUniqueFileResource(unique); @@ -2031,37 +2049,37 @@ MagickExport void ImageToCustomStream(const ImageInfo *image_info,Image *image, ThrowFileException(exception,BlobError,"UnableToWriteBlob", image_info->filename); blob=(unsigned char *) RelinquishMagickMemory(blob); - blob_info=DestroyImageInfo(blob_info); + clone_info=DestroyImageInfo(clone_info); return; } - blob_info->file=fdopen(file,"wb+"); - if (blob_info->file != (FILE *) NULL) + clone_info->file=fdopen(file,"wb+"); + if (clone_info->file != (FILE *) NULL) { ssize_t count; (void) FormatLocaleString(image->filename,MagickPathExtent, "%s:%s",image->magick,unique); - status=WriteImage(blob_info,image,exception); + status=WriteImage(clone_info,image,exception); (void) CloseBlob(image); if (status != MagickFalse) { - (void) fseek(blob_info->file,0,SEEK_SET); + (void) fseek(clone_info->file,0,SEEK_SET); count=(ssize_t) MagickMaxBufferExtent; while (count == (ssize_t) MagickMaxBufferExtent) { count=(ssize_t) fread(blob,sizeof(*blob),MagickMaxBufferExtent, - blob_info->file); + clone_info->file); (void) image_info->custom_stream->writer(blob,(size_t) count, image_info->custom_stream->data); } } - (void) fclose(blob_info->file); + (void) fclose(clone_info->file); } blob=(unsigned char *) RelinquishMagickMemory(blob); (void) RelinquishUniqueFileResource(unique); } - blob_info=DestroyImageInfo(blob_info); + clone_info=DestroyImageInfo(clone_info); } /* @@ -2221,7 +2239,7 @@ MagickExport void *ImagesToBlob(const ImageInfo *image_info,Image *images, *magick_info; ImageInfo - *blob_info; + *clone_info; MagickBooleanType status; @@ -2239,35 +2257,35 @@ MagickExport void *ImagesToBlob(const ImageInfo *image_info,Image *images, assert(exception != (ExceptionInfo *) NULL); *length=0; blob=(unsigned char *) NULL; - blob_info=CloneImageInfo(image_info); - (void) SetImageInfo(blob_info,(unsigned int) GetImageListLength(images), + clone_info=CloneImageInfo(image_info); + (void) SetImageInfo(clone_info,(unsigned int) GetImageListLength(images), exception); - if (*blob_info->magick != '\0') - (void) CopyMagickString(images->magick,blob_info->magick,MagickPathExtent); + if (*clone_info->magick != '\0') + (void) CopyMagickString(images->magick,clone_info->magick,MagickPathExtent); magick_info=GetMagickInfo(images->magick,exception); if (magick_info == (const MagickInfo *) NULL) { (void) ThrowMagickException(exception,GetMagickModule(), MissingDelegateError,"NoDecodeDelegateForThisImageFormat","`%s'", images->magick); - blob_info=DestroyImageInfo(blob_info); + clone_info=DestroyImageInfo(clone_info); return(blob); } if (GetMagickAdjoin(magick_info) == MagickFalse) { - blob_info=DestroyImageInfo(blob_info); + clone_info=DestroyImageInfo(clone_info); return(ImageToBlob(image_info,images,length,exception)); } - (void) CopyMagickString(blob_info->magick,images->magick,MagickPathExtent); + (void) CopyMagickString(clone_info->magick,images->magick,MagickPathExtent); if (GetMagickBlobSupport(magick_info) != MagickFalse) { /* Native blob support for this images format. */ - blob_info->length=0; - blob_info->blob=(void *) AcquireQuantumMemory(MagickMaxBlobExtent, + clone_info->length=0; + clone_info->blob=(void *) AcquireQuantumMemory(MagickMaxBlobExtent, sizeof(unsigned char)); - if (blob_info->blob == (void *) NULL) + if (clone_info->blob == (void *) NULL) (void) ThrowMagickException(exception,GetMagickModule(), ResourceLimitError,"MemoryAllocationFailed","`%s'",images->filename); else @@ -2275,7 +2293,7 @@ MagickExport void *ImagesToBlob(const ImageInfo *image_info,Image *images, (void) CloseBlob(images); images->blob->exempt=MagickTrue; *images->filename='\0'; - status=WriteImages(blob_info,images,images->filename,exception); + status=WriteImages(clone_info,images,images->filename,exception); *length=images->blob->length; blob=DetachBlob(images->blob); if (status == MagickFalse) @@ -2304,21 +2322,21 @@ MagickExport void *ImagesToBlob(const ImageInfo *image_info,Image *images, } else { - blob_info->file=fdopen(file,"wb"); - if (blob_info->file != (FILE *) NULL) + clone_info->file=fdopen(file,"wb"); + if (clone_info->file != (FILE *) NULL) { (void) FormatLocaleString(filename,MagickPathExtent,"%s:%s", images->magick,unique); - status=WriteImages(blob_info,images,filename,exception); + status=WriteImages(clone_info,images,filename,exception); (void) CloseBlob(images); - (void) fclose(blob_info->file); + (void) fclose(clone_info->file); if (status != MagickFalse) blob=FileToBlob(unique,~0UL,length,exception); } (void) RelinquishUniqueFileResource(unique); } } - blob_info=DestroyImageInfo(blob_info); + clone_info=DestroyImageInfo(clone_info); return(blob); } @@ -2357,7 +2375,7 @@ MagickExport void ImagesToCustomStream(const ImageInfo *image_info, *magick_info; ImageInfo - *blob_info; + *clone_info; MagickBooleanType status; @@ -2374,21 +2392,21 @@ MagickExport void ImagesToCustomStream(const ImageInfo *image_info, assert(image_info->custom_stream->reader != (CustomStreamHandler) NULL); assert(image_info->custom_stream->writer != (CustomStreamHandler) NULL); assert(exception != (ExceptionInfo *) NULL); - blob_info=CloneImageInfo(image_info); - (void) SetImageInfo(blob_info,(unsigned int) GetImageListLength(images), + clone_info=CloneImageInfo(image_info); + (void) SetImageInfo(clone_info,(unsigned int) GetImageListLength(images), exception); - if (*blob_info->magick != '\0') - (void) CopyMagickString(images->magick,blob_info->magick,MagickPathExtent); + if (*clone_info->magick != '\0') + (void) CopyMagickString(images->magick,clone_info->magick,MagickPathExtent); magick_info=GetMagickInfo(images->magick,exception); if (magick_info == (const MagickInfo *) NULL) { (void) ThrowMagickException(exception,GetMagickModule(), MissingDelegateError,"NoEncodeDelegateForThisImageFormat","`%s'", images->magick); - blob_info=DestroyImageInfo(blob_info); + clone_info=DestroyImageInfo(clone_info); return; } - (void) CopyMagickString(blob_info->magick,images->magick,MagickPathExtent); + (void) CopyMagickString(clone_info->magick,images->magick,MagickPathExtent); if (GetMagickBlobSupport(magick_info) != MagickFalse) { /* @@ -2396,7 +2414,7 @@ MagickExport void ImagesToCustomStream(const ImageInfo *image_info, */ (void) CloseBlob(images); *images->filename='\0'; - (void) WriteImages(blob_info,images,images->filename,exception); + (void) WriteImages(clone_info,images,images->filename,exception); (void) CloseBlob(images); } else @@ -2414,14 +2432,14 @@ MagickExport void ImagesToCustomStream(const ImageInfo *image_info, /* Write file to disk in blob image format. */ - blob_info->custom_stream=(CustomStreamInfo *) NULL; + clone_info->custom_stream=(CustomStreamInfo *) NULL; blob=(unsigned char *) AcquireQuantumMemory(MagickMaxBufferExtent, sizeof(*blob)); if (blob == (unsigned char *) NULL) { ThrowFileException(exception,BlobError,"UnableToWriteBlob", image_info->filename); - blob_info=DestroyImageInfo(blob_info); + clone_info=DestroyImageInfo(clone_info); return; } file=AcquireUniqueFileResource(unique); @@ -2430,38 +2448,37 @@ MagickExport void ImagesToCustomStream(const ImageInfo *image_info, ThrowFileException(exception,BlobError,"UnableToWriteBlob", image_info->filename); blob=(unsigned char *) RelinquishMagickMemory(blob); - blob_info=DestroyImageInfo(blob_info); + clone_info=DestroyImageInfo(clone_info); return; } - blob_info->file=fdopen(file,"wb+"); - if (blob_info->file != (FILE *) NULL) + clone_info->file=fdopen(file,"wb+"); + if (clone_info->file != (FILE *) NULL) { ssize_t count; (void) FormatLocaleString(filename,MagickPathExtent,"%s:%s", images->magick,unique); - status=WriteImages(blob_info,images,filename,exception); + status=WriteImages(clone_info,images,filename,exception); (void) CloseBlob(images); if (status != MagickFalse) { - (void) fseek(blob_info->file,0,SEEK_SET); + (void) fseek(clone_info->file,0,SEEK_SET); count=(ssize_t) MagickMaxBufferExtent; while (count == (ssize_t) MagickMaxBufferExtent) { count=(ssize_t) fread(blob,sizeof(*blob),MagickMaxBufferExtent, - blob_info->file); + clone_info->file); (void) image_info->custom_stream->writer(blob,(size_t) count, image_info->custom_stream->data); } } - (void) fclose(blob_info->file); + (void) fclose(clone_info->file); } blob=(unsigned char *) RelinquishMagickMemory(blob); (void) RelinquishUniqueFileResource(unique); } - blob_info=DestroyImageInfo(blob_info); - return; + clone_info=DestroyImageInfo(clone_info); } /* @@ -2675,6 +2692,9 @@ MagickExport MagickBooleanType IsBlobExempt(const Image *image) */ MagickExport MagickBooleanType IsBlobSeekable(const Image *image) { + BlobInfo + *restrict blob_info; + MagickBooleanType seekable; @@ -2682,7 +2702,8 @@ MagickExport MagickBooleanType IsBlobSeekable(const Image *image) assert(image->signature == MagickCoreSignature); if (image->debug != MagickFalse) (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); - switch (image->blob->type) + blob_info=image->blob; + switch (blob_info->type) { case FileStream: case BlobStream: @@ -2703,8 +2724,8 @@ MagickExport MagickBooleanType IsBlobSeekable(const Image *image) } case CustomStream: { - if ((image->blob->custom_stream->seeker != (CustomStreamSeeker) NULL) && - (image->blob->custom_stream->teller != (CustomStreamTeller) NULL)) + if ((blob_info->custom_stream->seeker != (CustomStreamSeeker) NULL) && + (blob_info->custom_stream->teller != (CustomStreamTeller) NULL)) seekable=MagickTrue; else seekable=MagickFalse; @@ -2987,6 +3008,9 @@ static inline MagickBooleanType SetStreamBuffering(const ImageInfo *image_info, MagickExport MagickBooleanType OpenBlob(const ImageInfo *image_info, Image *image,const BlobMode mode,ExceptionInfo *exception) { + BlobInfo + *restrict blob_info; + char extension[MagickPathExtent], filename[MagickPathExtent]; @@ -3007,21 +3031,22 @@ MagickExport MagickBooleanType OpenBlob(const ImageInfo *image_info, image_info->filename); assert(image != (Image *) NULL); assert(image->signature == MagickCoreSignature); + blob_info=image->blob; if (image_info->blob != (void *) NULL) { if (image_info->stream != (StreamHandler) NULL) - image->blob->stream=(StreamHandler) image_info->stream; - AttachBlob(image->blob,image_info->blob,image_info->length); + blob_info->stream=(StreamHandler) image_info->stream; + AttachBlob(blob_info,image_info->blob,image_info->length); return(MagickTrue); } if ((image_info->custom_stream != (CustomStreamInfo *) NULL) && (*image->filename == '\0')) { - image->blob->type=CustomStream; - image->blob->custom_stream=image_info->custom_stream; + blob_info->type=CustomStream; + blob_info->custom_stream=image_info->custom_stream; return(MagickTrue); } - (void) DetachBlob(image->blob); + (void) DetachBlob(blob_info); switch (mode) { default: type="r"; break; @@ -3033,13 +3058,13 @@ MagickExport MagickBooleanType OpenBlob(const ImageInfo *image_info, case AppendBinaryBlobMode: type="a+b"; break; } if (*type != 'r') - image->blob->synchronize=image_info->synchronize; + blob_info->synchronize=image_info->synchronize; if (image_info->stream != (StreamHandler) NULL) { - image->blob->stream=image_info->stream; + blob_info->stream=image_info->stream; if (*type == 'w') { - image->blob->type=FifoStream; + blob_info->type=FifoStream; return(MagickTrue); } } @@ -3061,13 +3086,13 @@ MagickExport MagickBooleanType OpenBlob(const ImageInfo *image_info, if ((LocaleCompare(filename,"-") == 0) || ((*filename == '\0') && (image_info->file == (FILE *) NULL))) { - image->blob->file_info.file=(*type == 'r') ? stdin : stdout; + blob_info->file_info.file=(*type == 'r') ? stdin : stdout; #if defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__OS2__) if (strchr(type,'b') != (char *) NULL) - setmode(fileno(image->blob->file_info.file),_O_BINARY); + setmode(fileno(blob_info->file_info.file),_O_BINARY); #endif - image->blob->type=StandardStream; - image->blob->exempt=MagickTrue; + blob_info->type=StandardStream; + blob_info->exempt=MagickTrue; return(SetStreamBuffering(image_info,image)); } if (LocaleNCompare(filename,"fd:",3) == 0) @@ -3077,13 +3102,13 @@ MagickExport MagickBooleanType OpenBlob(const ImageInfo *image_info, *fileMode =(*type); fileMode[1]='\0'; - image->blob->file_info.file=fdopen(StringToLong(filename+3),fileMode); + blob_info->file_info.file=fdopen(StringToLong(filename+3),fileMode); #if defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__OS2__) if (strchr(type,'b') != (char *) NULL) - setmode(fileno(image->blob->file_info.file),_O_BINARY); + setmode(fileno(blob_info->file_info.file),_O_BINARY); #endif - image->blob->type=StandardStream; - image->blob->exempt=MagickTrue; + blob_info->type=StandardStream; + blob_info->exempt=MagickTrue; return(SetStreamBuffering(image_info,image)); } #if defined(MAGICKCORE_HAVE_POPEN) && defined(MAGICKCORE_PIPES_SUPPORT) @@ -3103,31 +3128,30 @@ MagickExport MagickBooleanType OpenBlob(const ImageInfo *image_info, *fileMode =(*type); fileMode[1]='\0'; sanitize_command=SanitizeString(filename+1); - image->blob->file_info.file=(FILE *) popen_utf8(sanitize_command, - fileMode); + blob_info->file_info.file=(FILE *) popen_utf8(sanitize_command,fileMode); sanitize_command=DestroyString(sanitize_command); - if (image->blob->file_info.file == (FILE *) NULL) + if (blob_info->file_info.file == (FILE *) NULL) { ThrowFileException(exception,BlobError,"UnableToOpenBlob",filename); return(MagickFalse); } - image->blob->type=PipeStream; - image->blob->exempt=MagickTrue; + blob_info->type=PipeStream; + blob_info->exempt=MagickTrue; return(SetStreamBuffering(image_info,image)); } #endif - status=GetPathAttributes(filename,&image->blob->properties); + status=GetPathAttributes(filename,&blob_info->properties); #if defined(S_ISFIFO) - if ((status != MagickFalse) && S_ISFIFO(image->blob->properties.st_mode)) + if ((status != MagickFalse) && S_ISFIFO(blob_info->properties.st_mode)) { - image->blob->file_info.file=(FILE *) fopen_utf8(filename,type); - if (image->blob->file_info.file == (FILE *) NULL) + blob_info->file_info.file=(FILE *) fopen_utf8(filename,type); + if (blob_info->file_info.file == (FILE *) NULL) { ThrowFileException(exception,BlobError,"UnableToOpenBlob",filename); return(MagickFalse); } - image->blob->type=FileStream; - image->blob->exempt=MagickTrue; + blob_info->type=FileStream; + blob_info->exempt=MagickTrue; return(SetStreamBuffering(image_info,image)); } #endif @@ -3166,15 +3190,15 @@ MagickExport MagickBooleanType OpenBlob(const ImageInfo *image_info, } if (image_info->file != (FILE *) NULL) { - image->blob->file_info.file=image_info->file; - image->blob->type=FileStream; - image->blob->exempt=MagickTrue; + blob_info->file_info.file=image_info->file; + blob_info->type=FileStream; + blob_info->exempt=MagickTrue; } else if (*type == 'r') { - image->blob->file_info.file=(FILE *) fopen_utf8(filename,type); - if (image->blob->file_info.file != (FILE *) NULL) + blob_info->file_info.file=(FILE *) fopen_utf8(filename,type); + if (blob_info->file_info.file != (FILE *) NULL) { size_t count; @@ -3182,13 +3206,13 @@ MagickExport MagickBooleanType OpenBlob(const ImageInfo *image_info, unsigned char magick[3]; - image->blob->type=FileStream; + blob_info->type=FileStream; (void) SetStreamBuffering(image_info,image); (void) ResetMagickMemory(magick,0,sizeof(magick)); - count=fread(magick,1,sizeof(magick),image->blob->file_info.file); - (void) fseek(image->blob->file_info.file,-((off_t) count),SEEK_CUR); + count=fread(magick,1,sizeof(magick),blob_info->file_info.file); + (void) fseek(blob_info->file_info.file,-((off_t) count),SEEK_CUR); #if defined(MAGICKCORE_POSIX_SUPPORT) - (void) fflush(image->blob->file_info.file); + (void) fflush(blob_info->file_info.file); #endif (void) LogMagickEvent(BlobEvent,GetMagickModule(), " read %.20g magic header bytes",(double) count); @@ -3196,26 +3220,26 @@ MagickExport MagickBooleanType OpenBlob(const ImageInfo *image_info, if (((int) magick[0] == 0x1F) && ((int) magick[1] == 0x8B) && ((int) magick[2] == 0x08)) { - if (image->blob->file_info.file != (FILE *) NULL) - (void) fclose(image->blob->file_info.file); - image->blob->file_info.file=(FILE *) NULL; - image->blob->file_info.gzfile=gzopen(filename,type); - if (image->blob->file_info.gzfile != (gzFile) NULL) - image->blob->type=ZipStream; + if (blob_info->file_info.file != (FILE *) NULL) + (void) fclose(blob_info->file_info.file); + blob_info->file_info.file=(FILE *) NULL; + blob_info->file_info.gzfile=gzopen(filename,type); + if (blob_info->file_info.gzfile != (gzFile) NULL) + blob_info->type=ZipStream; } #endif #if defined(MAGICKCORE_BZLIB_DELEGATE) if (strncmp((char *) magick,"BZh",3) == 0) { - if (image->blob->file_info.file != (FILE *) NULL) - (void) fclose(image->blob->file_info.file); - image->blob->file_info.file=(FILE *) NULL; - image->blob->file_info.bzfile=BZ2_bzopen(filename,type); - if (image->blob->file_info.bzfile != (BZFILE *) NULL) - image->blob->type=BZipStream; + if (blob_info->file_info.file != (FILE *) NULL) + (void) fclose(blob_info->file_info.file); + blob_info->file_info.file=(FILE *) NULL; + blob_info->file_info.bzfile=BZ2_bzopen(filename,type); + if (blob_info->file_info.bzfile != (BZFILE *) NULL) + blob_info->type=BZipStream; } #endif - if (image->blob->type == FileStream) + if (blob_info->type == FileStream) { const MagickInfo *magick_info; @@ -3229,7 +3253,7 @@ MagickExport MagickBooleanType OpenBlob(const ImageInfo *image_info, sans_exception=AcquireExceptionInfo(); magick_info=GetMagickInfo(image_info->magick,sans_exception); sans_exception=DestroyExceptionInfo(sans_exception); - length=(size_t) image->blob->properties.st_size; + length=(size_t) blob_info->properties.st_size; if ((magick_info != (const MagickInfo *) NULL) && (GetMagickBlobSupport(magick_info) != MagickFalse) && (length > MagickMaxBufferExtent) && @@ -3238,7 +3262,7 @@ MagickExport MagickBooleanType OpenBlob(const ImageInfo *image_info, void *blob; - blob=MapBlob(fileno(image->blob->file_info.file),ReadMode,0, + blob=MapBlob(fileno(blob_info->file_info.file),ReadMode,0, length); if (blob == (void *) NULL) RelinquishMagickResource(MapResource,length); @@ -3248,14 +3272,14 @@ MagickExport MagickBooleanType OpenBlob(const ImageInfo *image_info, Format supports blobs-- use memory-mapped I/O. */ if (image_info->file != (FILE *) NULL) - image->blob->exempt=MagickFalse; + blob_info->exempt=MagickFalse; else { - (void) fclose(image->blob->file_info.file); - image->blob->file_info.file=(FILE *) NULL; + (void) fclose(blob_info->file_info.file); + blob_info->file_info.file=(FILE *) NULL; } - AttachBlob(image->blob,blob,length); - image->blob->mapped=MagickTrue; + AttachBlob(blob_info,blob,length); + blob_info->mapped=MagickTrue; } } } @@ -3270,32 +3294,32 @@ MagickExport MagickBooleanType OpenBlob(const ImageInfo *image_info, { if (mode == WriteBinaryBlobMode) type="wb"; - image->blob->file_info.gzfile=gzopen(filename,type); - if (image->blob->file_info.gzfile != (gzFile) NULL) - image->blob->type=ZipStream; + blob_info->file_info.gzfile=gzopen(filename,type); + if (blob_info->file_info.gzfile != (gzFile) NULL) + blob_info->type=ZipStream; } else #endif #if defined(MAGICKCORE_BZLIB_DELEGATE) if (LocaleCompare(extension,"bz2") == 0) { - image->blob->file_info.bzfile=BZ2_bzopen(filename,type); - if (image->blob->file_info.bzfile != (BZFILE *) NULL) - image->blob->type=BZipStream; + blob_info->file_info.bzfile=BZ2_bzopen(filename,type); + if (blob_info->file_info.bzfile != (BZFILE *) NULL) + blob_info->type=BZipStream; } else #endif { - image->blob->file_info.file=(FILE *) fopen_utf8(filename,type); - if (image->blob->file_info.file != (FILE *) NULL) + blob_info->file_info.file=(FILE *) fopen_utf8(filename,type); + if (blob_info->file_info.file != (FILE *) NULL) { - image->blob->type=FileStream; + blob_info->type=FileStream; (void) SetStreamBuffering(image_info,image); } } - image->blob->status=MagickFalse; - if (image->blob->type != UndefinedStream) - image->blob->size=GetBlobSize(image); + blob_info->status=MagickFalse; + if (blob_info->type != UndefinedStream) + blob_info->size=GetBlobSize(image); else { ThrowFileException(exception,BlobError,"UnableToOpenBlob",filename); @@ -3425,6 +3449,9 @@ MagickExport Image *PingBlob(const ImageInfo *image_info,const void *blob, */ MagickExport ssize_t ReadBlob(Image *image,const size_t length,void *data) { + BlobInfo + *restrict blob_info; + int c; @@ -3441,9 +3468,10 @@ MagickExport ssize_t ReadBlob(Image *image,const size_t length,void *data) if (length == 0) return(0); assert(data != (void *) NULL); + blob_info=image->blob; count=0; q=(unsigned char *) data; - switch (image->blob->type) + switch (blob_info->type) { case UndefinedStream: break; @@ -3455,12 +3483,12 @@ MagickExport ssize_t ReadBlob(Image *image,const size_t length,void *data) { default: { - count=(ssize_t) fread(q,1,length,image->blob->file_info.file); + count=(ssize_t) fread(q,1,length,blob_info->file_info.file); break; } case 4: { - c=getc(image->blob->file_info.file); + c=getc(blob_info->file_info.file); if (c == EOF) break; *q++=(unsigned char) c; @@ -3468,7 +3496,7 @@ MagickExport ssize_t ReadBlob(Image *image,const size_t length,void *data) } case 3: { - c=getc(image->blob->file_info.file); + c=getc(blob_info->file_info.file); if (c == EOF) break; *q++=(unsigned char) c; @@ -3476,7 +3504,7 @@ MagickExport ssize_t ReadBlob(Image *image,const size_t length,void *data) } case 2: { - c=getc(image->blob->file_info.file); + c=getc(blob_info->file_info.file); if (c == EOF) break; *q++=(unsigned char) c; @@ -3484,7 +3512,7 @@ MagickExport ssize_t ReadBlob(Image *image,const size_t length,void *data) } case 1: { - c=getc(image->blob->file_info.file); + c=getc(blob_info->file_info.file); if (c == EOF) break; *q++=(unsigned char) c; @@ -3502,13 +3530,13 @@ MagickExport ssize_t ReadBlob(Image *image,const size_t length,void *data) { default: { - count=(ssize_t) gzread(image->blob->file_info.gzfile,q, + count=(ssize_t) gzread(blob_info->file_info.gzfile,q, (unsigned int) length); break; } case 4: { - c=gzgetc(image->blob->file_info.gzfile); + c=gzgetc(blob_info->file_info.gzfile); if (c == EOF) break; *q++=(unsigned char) c; @@ -3516,7 +3544,7 @@ MagickExport ssize_t ReadBlob(Image *image,const size_t length,void *data) } case 3: { - c=gzgetc(image->blob->file_info.gzfile); + c=gzgetc(blob_info->file_info.gzfile); if (c == EOF) break; *q++=(unsigned char) c; @@ -3524,7 +3552,7 @@ MagickExport ssize_t ReadBlob(Image *image,const size_t length,void *data) } case 2: { - c=gzgetc(image->blob->file_info.gzfile); + c=gzgetc(blob_info->file_info.gzfile); if (c == EOF) break; *q++=(unsigned char) c; @@ -3532,7 +3560,7 @@ MagickExport ssize_t ReadBlob(Image *image,const size_t length,void *data) } case 1: { - c=gzgetc(image->blob->file_info.gzfile); + c=gzgetc(blob_info->file_info.gzfile); if (c == EOF) break; *q++=(unsigned char) c; @@ -3547,7 +3575,7 @@ MagickExport ssize_t ReadBlob(Image *image,const size_t length,void *data) case BZipStream: { #if defined(MAGICKCORE_BZLIB_DELEGATE) - count=(ssize_t) BZ2_bzread(image->blob->file_info.bzfile,q,(int) length); + count=(ssize_t) BZ2_bzread(blob_info->file_info.bzfile,q,(int) length); #endif break; } @@ -3558,25 +3586,25 @@ MagickExport ssize_t ReadBlob(Image *image,const size_t length,void *data) register const unsigned char *p; - if (image->blob->offset >= (MagickOffsetType) image->blob->length) + if (blob_info->offset >= (MagickOffsetType) blob_info->length) { - image->blob->eof=MagickTrue; + blob_info->eof=MagickTrue; break; } - p=image->blob->data+image->blob->offset; + p=blob_info->data+blob_info->offset; count=(ssize_t) MagickMin((MagickOffsetType) length,(MagickOffsetType) - image->blob->length-image->blob->offset); - image->blob->offset+=count; + blob_info->length-blob_info->offset); + blob_info->offset+=count; if (count != (ssize_t) length) - image->blob->eof=MagickTrue; + blob_info->eof=MagickTrue; (void) memcpy(q,p,(size_t) count); break; } case CustomStream: { - if (image->blob->custom_stream->reader != (CustomStreamHandler) NULL) - count=image->blob->custom_stream->reader(q,length, - image->blob->custom_stream->data); + if (blob_info->custom_stream->reader != (CustomStreamHandler) NULL) + count=blob_info->custom_stream->reader(q,length, + blob_info->custom_stream->data); break; } } @@ -4558,13 +4586,17 @@ MagickExport BlobInfo *ReferenceBlob(BlobInfo *blob) MagickExport MagickOffsetType SeekBlob(Image *image, const MagickOffsetType offset,const int whence) { + BlobInfo + *restrict blob_info; + assert(image != (Image *) NULL); assert(image->signature == MagickCoreSignature); if (image->debug != MagickFalse) (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); assert(image->blob != (BlobInfo *) NULL); assert(image->blob->type != UndefinedStream); - switch (image->blob->type) + blob_info=image->blob; + switch (blob_info->type) { case UndefinedStream: break; @@ -4575,18 +4607,18 @@ MagickExport MagickOffsetType SeekBlob(Image *image, { if ((offset < 0) && (whence == SEEK_SET)) return(-1); - if (fseek(image->blob->file_info.file,offset,whence) < 0) + if (fseek(blob_info->file_info.file,offset,whence) < 0) return(-1); - image->blob->offset=TellBlob(image); + blob_info->offset=TellBlob(image); break; } case ZipStream: { #if defined(MAGICKCORE_ZLIB_DELEGATE) - if (gzseek(image->blob->file_info.gzfile,(off_t) offset,whence) < 0) + if (gzseek(blob_info->file_info.gzfile,(off_t) offset,whence) < 0) return(-1); #endif - image->blob->offset=TellBlob(image); + blob_info->offset=TellBlob(image); break; } case BZipStream: @@ -4602,60 +4634,58 @@ MagickExport MagickOffsetType SeekBlob(Image *image, { if (offset < 0) return(-1); - image->blob->offset=offset; + blob_info->offset=offset; break; } case SEEK_CUR: { - if ((image->blob->offset+offset) < 0) + if ((blob_info->offset+offset) < 0) return(-1); - image->blob->offset+=offset; + blob_info->offset+=offset; break; } case SEEK_END: { - if (((MagickOffsetType) image->blob->length+offset) < 0) + if (((MagickOffsetType) blob_info->length+offset) < 0) return(-1); - image->blob->offset=image->blob->length+offset; + blob_info->offset=blob_info->length+offset; break; } } - if (image->blob->offset < (MagickOffsetType) - ((off_t) image->blob->length)) + if (blob_info->offset < (MagickOffsetType) ((off_t) blob_info->length)) { - image->blob->eof=MagickFalse; + blob_info->eof=MagickFalse; break; } - if (image->blob->offset < (MagickOffsetType) - ((off_t) image->blob->extent)) + if (blob_info->offset < (MagickOffsetType) ((off_t) blob_info->extent)) break; - if (image->blob->mapped != MagickFalse) + if (blob_info->mapped != MagickFalse) { - image->blob->eof=MagickTrue; + blob_info->eof=MagickTrue; return(-1); } - image->blob->extent=(size_t) (image->blob->offset+image->blob->quantum); - image->blob->quantum<<=1; - image->blob->data=(unsigned char *) ResizeQuantumMemory(image->blob->data, - image->blob->extent+1,sizeof(*image->blob->data)); + blob_info->extent=(size_t) (blob_info->offset+blob_info->quantum); + blob_info->quantum<<=1; + blob_info->data=(unsigned char *) ResizeQuantumMemory(blob_info->data, + blob_info->extent+1,sizeof(*blob_info->data)); (void) SyncBlob(image); - if (image->blob->data == NULL) + if (blob_info->data == NULL) { - (void) DetachBlob(image->blob); + (void) DetachBlob(blob_info); return(-1); } break; } case CustomStream: { - if (image->blob->custom_stream->seeker == (CustomStreamSeeker) NULL) + if (blob_info->custom_stream->seeker == (CustomStreamSeeker) NULL) return(-1); - image->blob->offset=image->blob->custom_stream->seeker(offset,whence, - image->blob->custom_stream->data); + blob_info->offset=blob_info->custom_stream->seeker(offset,whence, + blob_info->custom_stream->data); break; } } - return(image->blob->offset); + return(blob_info->offset); } /* @@ -4721,13 +4751,17 @@ MagickExport void SetBlobExempt(Image *image,const MagickBooleanType exempt) MagickExport MagickBooleanType SetBlobExtent(Image *image, const MagickSizeType extent) { + BlobInfo + *restrict blob_info; + assert(image != (Image *) NULL); assert(image->signature == MagickCoreSignature); if (image->debug != MagickFalse) (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); assert(image->blob != (BlobInfo *) NULL); assert(image->blob->type != UndefinedStream); - switch (image->blob->type) + blob_info=image->blob; + switch (blob_info->type) { case UndefinedStream: break; @@ -4752,14 +4786,14 @@ MagickExport MagickBooleanType SetBlobExtent(Image *image, if (offset < 0) break; count=(ssize_t) fwrite((const unsigned char *) "",1,1, - image->blob->file_info.file); + blob_info->file_info.file); #if defined(MAGICKCORE_HAVE_POSIX_FALLOCATE) - if (image->blob->synchronize != MagickFalse) + if (blob_info->synchronize != MagickFalse) { int file; - file=fileno(image->blob->file_info.file); + file=fileno(blob_info->file_info.file); if ((file == -1) || (offset < 0)) return(MagickFalse); (void) posix_fallocate(file,offset,extent-offset); @@ -4781,7 +4815,7 @@ MagickExport MagickBooleanType SetBlobExtent(Image *image, { if (extent != (MagickSizeType) ((size_t) extent)) return(MagickFalse); - if (image->blob->mapped != MagickFalse) + if (blob_info->mapped != MagickFalse) { MagickOffsetType offset; @@ -4789,8 +4823,8 @@ MagickExport MagickBooleanType SetBlobExtent(Image *image, ssize_t count; - (void) UnmapBlob(image->blob->data,image->blob->length); - RelinquishMagickResource(MapResource,image->blob->length); + (void) UnmapBlob(blob_info->data,blob_info->length); + RelinquishMagickResource(MapResource,blob_info->length); if (extent != (MagickSizeType) ((off_t) extent)) return(MagickFalse); offset=SeekBlob(image,0,SEEK_END); @@ -4800,14 +4834,14 @@ MagickExport MagickBooleanType SetBlobExtent(Image *image, break; offset=SeekBlob(image,(MagickOffsetType) extent-1,SEEK_SET); count=(ssize_t) fwrite((const unsigned char *) "",1,1, - image->blob->file_info.file); + blob_info->file_info.file); #if defined(MAGICKCORE_HAVE_POSIX_FALLOCATE) - if (image->blob->synchronize != MagickFalse) + if (blob_info->synchronize != MagickFalse) { int file; - file=fileno(image->blob->file_info.file); + file=fileno(blob_info->file_info.file); if ((file == -1) || (offset < 0)) return(MagickFalse); (void) posix_fallocate(file,offset,extent-offset); @@ -4817,20 +4851,20 @@ MagickExport MagickBooleanType SetBlobExtent(Image *image, if (count != 1) return(MagickFalse); (void) AcquireMagickResource(MapResource,extent); - image->blob->data=(unsigned char*) MapBlob(fileno( - image->blob->file_info.file),WriteMode,0,(size_t) extent); - image->blob->extent=(size_t) extent; - image->blob->length=(size_t) extent; + blob_info->data=(unsigned char*) MapBlob(fileno( + blob_info->file_info.file),WriteMode,0,(size_t) extent); + blob_info->extent=(size_t) extent; + blob_info->length=(size_t) extent; (void) SyncBlob(image); break; } - image->blob->extent=(size_t) extent; - image->blob->data=(unsigned char *) ResizeQuantumMemory(image->blob->data, - image->blob->extent+1,sizeof(*image->blob->data)); + blob_info->extent=(size_t) extent; + blob_info->data=(unsigned char *) ResizeQuantumMemory(blob_info->data, + blob_info->extent+1,sizeof(*blob_info->data)); (void) SyncBlob(image); - if (image->blob->data == (unsigned char *) NULL) + if (blob_info->data == (unsigned char *) NULL) { - (void) DetachBlob(image->blob); + (void) DetachBlob(blob_info); return(MagickFalse); } break; @@ -5030,6 +5064,9 @@ MagickExport void SetCustomStreamWriter(CustomStreamInfo *custom_stream, */ static int SyncBlob(Image *image) { + BlobInfo + *restrict blob_info; + int status; @@ -5039,8 +5076,9 @@ static int SyncBlob(Image *image) (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); assert(image->blob != (BlobInfo *) NULL); assert(image->blob->type != UndefinedStream); + blob_info=image->blob; status=0; - switch (image->blob->type) + switch (blob_info->type) { case UndefinedStream: case StandardStream: @@ -5048,20 +5086,20 @@ static int SyncBlob(Image *image) case FileStream: case PipeStream: { - status=fflush(image->blob->file_info.file); + status=fflush(blob_info->file_info.file); break; } case ZipStream: { #if defined(MAGICKCORE_ZLIB_DELEGATE) - status=gzflush(image->blob->file_info.gzfile,Z_SYNC_FLUSH); + status=gzflush(blob_info->file_info.gzfile,Z_SYNC_FLUSH); #endif break; } case BZipStream: { #if defined(MAGICKCORE_BZLIB_DELEGATE) - status=BZ2_bzflush(image->blob->file_info.bzfile); + status=BZ2_bzflush(blob_info->file_info.bzfile); #endif break; } @@ -5099,6 +5137,9 @@ static int SyncBlob(Image *image) */ MagickExport MagickOffsetType TellBlob(const Image *image) { + BlobInfo + *restrict blob_info; + MagickOffsetType offset; @@ -5108,15 +5149,16 @@ MagickExport MagickOffsetType TellBlob(const Image *image) (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); assert(image->blob != (BlobInfo *) NULL); assert(image->blob->type != UndefinedStream); + blob_info=image->blob; offset=(-1); - switch (image->blob->type) + switch (blob_info->type) { case UndefinedStream: case StandardStream: break; case FileStream: { - offset=ftell(image->blob->file_info.file); + offset=ftell(blob_info->file_info.file); break; } case PipeStream: @@ -5124,7 +5166,7 @@ MagickExport MagickOffsetType TellBlob(const Image *image) case ZipStream: { #if defined(MAGICKCORE_ZLIB_DELEGATE) - offset=(MagickOffsetType) gztell(image->blob->file_info.gzfile); + offset=(MagickOffsetType) gztell(blob_info->file_info.gzfile); #endif break; } @@ -5134,13 +5176,13 @@ MagickExport MagickOffsetType TellBlob(const Image *image) break; case BlobStream: { - offset=image->blob->offset; + offset=blob_info->offset; break; } case CustomStream: { - if (image->blob->custom_stream->teller != (CustomStreamTeller) NULL) - offset=image->blob->custom_stream->teller(image->blob->custom_stream->data); + if (blob_info->custom_stream->teller != (CustomStreamTeller) NULL) + offset=blob_info->custom_stream->teller(blob_info->custom_stream->data); break; } } @@ -5218,6 +5260,9 @@ MagickExport MagickBooleanType UnmapBlob(void *map,const size_t length) MagickExport ssize_t WriteBlob(Image *image,const size_t length, const void *data) { + BlobInfo + *restrict blob_info; + int c; @@ -5234,9 +5279,10 @@ MagickExport ssize_t WriteBlob(Image *image,const size_t length, if (length == 0) return(0); assert(data != (const void *) NULL); + blob_info=image->blob; count=0; p=(const unsigned char *) data; - switch (image->blob->type) + switch (blob_info->type) { case UndefinedStream: break; @@ -5249,33 +5295,33 @@ MagickExport ssize_t WriteBlob(Image *image,const size_t length, default: { count=(ssize_t) fwrite((const char *) data,1,length, - image->blob->file_info.file); + blob_info->file_info.file); break; } case 4: { - c=putc((int) *p++,image->blob->file_info.file); + c=putc((int) *p++,blob_info->file_info.file); if (c == EOF) break; count++; } case 3: { - c=putc((int) *p++,image->blob->file_info.file); + c=putc((int) *p++,blob_info->file_info.file); if (c == EOF) break; count++; } case 2: { - c=putc((int) *p++,image->blob->file_info.file); + c=putc((int) *p++,blob_info->file_info.file); if (c == EOF) break; count++; } case 1: { - c=putc((int) *p++,image->blob->file_info.file); + c=putc((int) *p++,blob_info->file_info.file); if (c == EOF) break; count++; @@ -5292,34 +5338,34 @@ MagickExport ssize_t WriteBlob(Image *image,const size_t length, { default: { - count=(ssize_t) gzwrite(image->blob->file_info.gzfile,(void *) data, + count=(ssize_t) gzwrite(blob_info->file_info.gzfile,(void *) data, (unsigned int) length); break; } case 4: { - c=gzputc(image->blob->file_info.gzfile,(int) *p++); + c=gzputc(blob_info->file_info.gzfile,(int) *p++); if (c == EOF) break; count++; } case 3: { - c=gzputc(image->blob->file_info.gzfile,(int) *p++); + c=gzputc(blob_info->file_info.gzfile,(int) *p++); if (c == EOF) break; count++; } case 2: { - c=gzputc(image->blob->file_info.gzfile,(int) *p++); + c=gzputc(blob_info->file_info.gzfile,(int) *p++); if (c == EOF) break; count++; } case 1: { - c=gzputc(image->blob->file_info.gzfile,(int) *p++); + c=gzputc(blob_info->file_info.gzfile,(int) *p++); if (c == EOF) break; count++; @@ -5333,14 +5379,14 @@ MagickExport ssize_t WriteBlob(Image *image,const size_t length, case BZipStream: { #if defined(MAGICKCORE_BZLIB_DELEGATE) - count=(ssize_t) BZ2_bzwrite(image->blob->file_info.bzfile,(void *) data, + count=(ssize_t) BZ2_bzwrite(blob_info->file_info.bzfile,(void *) data, (int) length); #endif break; } case FifoStream: { - count=(ssize_t) image->blob->stream(image,data,length); + count=(ssize_t) blob_info->stream(image,data,length); break; } case BlobStream: @@ -5348,35 +5394,35 @@ MagickExport ssize_t WriteBlob(Image *image,const size_t length, register unsigned char *q; - if ((image->blob->offset+(MagickOffsetType) length) >= - (MagickOffsetType) image->blob->extent) + if ((blob_info->offset+(MagickOffsetType) length) >= + (MagickOffsetType) blob_info->extent) { - if (image->blob->mapped != MagickFalse) + if (blob_info->mapped != MagickFalse) return(0); - image->blob->extent+=length+image->blob->quantum; - image->blob->quantum<<=1; - image->blob->data=(unsigned char *) ResizeQuantumMemory( - image->blob->data,image->blob->extent+1,sizeof(*image->blob->data)); + blob_info->extent+=length+blob_info->quantum; + blob_info->quantum<<=1; + blob_info->data=(unsigned char *) ResizeQuantumMemory( + blob_info->data,blob_info->extent+1,sizeof(*blob_info->data)); (void) SyncBlob(image); - if (image->blob->data == (unsigned char *) NULL) + if (blob_info->data == (unsigned char *) NULL) { - (void) DetachBlob(image->blob); + (void) DetachBlob(blob_info); return(0); } } - q=image->blob->data+image->blob->offset; + q=blob_info->data+blob_info->offset; (void) memcpy(q,p,length); - image->blob->offset+=length; - if (image->blob->offset >= (MagickOffsetType) image->blob->length) - image->blob->length=(size_t) image->blob->offset; + blob_info->offset+=length; + if (blob_info->offset >= (MagickOffsetType) blob_info->length) + blob_info->length=(size_t) blob_info->offset; count=(ssize_t) length; break; } case CustomStream: { - if (image->blob->custom_stream->writer != (CustomStreamHandler) NULL) - count=image->blob->custom_stream->writer((unsigned char *) data, - length,image->blob->custom_stream->data); + if (blob_info->custom_stream->writer != (CustomStreamHandler) NULL) + count=blob_info->custom_stream->writer((unsigned char *) data, + length,blob_info->custom_stream->data); break; } } diff --git a/coders/png.c b/coders/png.c index e87c1d9d6..28b7d4ee7 100644 --- a/coders/png.c +++ b/coders/png.c @@ -4981,6 +4981,8 @@ static Image *ReadOneJNGImage(MngInfo *mng_info, { s=GetVirtualPixels(jng_image,0,y,image->columns,1,exception); q=GetAuthenticPixels(image,0,y,image->columns,1,exception); + if ((s == (const Quantum *) NULL) || (q == (Quantum *) NULL)) + break; for (x=(ssize_t) image->columns; x != 0; x--) { SetPixelRed(image,GetPixelRed(jng_image,s),q); @@ -5023,9 +5025,10 @@ static Image *ReadOneJNGImage(MngInfo *mng_info, if (jng_image != (Image *) NULL) for (y=0; y < (ssize_t) image->rows; y++) { - s=GetVirtualPixels(jng_image,0,y,image->columns,1, - exception); + s=GetVirtualPixels(jng_image,0,y,image->columns,1,exception); q=GetAuthenticPixels(image,0,y,image->columns,1,exception); + if ((s == (const Quantum *) NULL) || (q == (Quantum *) NULL)) + break; if (image->alpha_trait != UndefinedPixelTrait) for (x=(ssize_t) image->columns; x != 0; x--)