From 9ef63ad7d60d7e24e1a052c022b8ea6b010ead1c Mon Sep 17 00:00:00 2001 From: Cristy Date: Wed, 26 Dec 2018 12:49:53 -0500 Subject: [PATCH] Experiment fail-- restore previous mods --- MagickCore/cache.c | 60 +++++++++++++++++++++++++-------------------- MagickCore/memory.c | 27 ++++++++------------ 2 files changed, 43 insertions(+), 44 deletions(-) diff --git a/MagickCore/cache.c b/MagickCore/cache.c index de9e9d925..554d8e781 100644 --- a/MagickCore/cache.c +++ b/MagickCore/cache.c @@ -190,9 +190,7 @@ MagickPrivate Cache AcquirePixelCache(const size_t number_threads) char *value; - cache_info=(CacheInfo *) AcquireAlignedMemory(1,sizeof(*cache_info)); - if (cache_info == (CacheInfo *) NULL) - ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed"); + cache_info=(CacheInfo *) AcquireCriticalMemory(sizeof(*cache_info)); (void) memset(cache_info,0,sizeof(*cache_info)); cache_info->type=UndefinedCache; cache_info->mode=IOMode; @@ -1070,7 +1068,7 @@ MagickPrivate Cache DestroyPixelCache(Cache cache) if (cache_info->semaphore != (SemaphoreInfo *) NULL) RelinquishSemaphoreInfo(&cache_info->semaphore); cache_info->signature=(~MagickCoreSignature); - cache_info=(CacheInfo *) RelinquishAlignedMemory(cache_info); + cache_info=(CacheInfo *) RelinquishMagickMemory(cache_info); cache=(Cache) NULL; return(cache); } @@ -1112,7 +1110,6 @@ static inline void RelinquishCacheNexusPixels(NexusInfo *nexus_info) nexus_info->metacontent=(void *) NULL; nexus_info->length=0; nexus_info->mapped=MagickFalse; - nexus_info->authentic_pixel_cache=MagickFalse; } MagickPrivate NexusInfo **DestroyPixelCacheNexus(NexusInfo **nexus_info, @@ -2797,11 +2794,11 @@ MagickPrivate const Quantum *GetVirtualPixelCacheNexus(const Image *image, MagickBooleanType status; - if (nexus_info->authentic_pixel_cache != MagickFalse) - return(q); /* Pixel request is inside cache extents. */ + if (nexus_info->authentic_pixel_cache != MagickFalse) + return(q); status=ReadPixelCachePixels(cache_info,nexus_info,exception); if (status == MagickFalse) return((const Quantum *) NULL); @@ -4964,25 +4961,24 @@ MagickPrivate void SetPixelCacheMethods(Cache cache,CacheMethods *cache_methods) */ static inline MagickBooleanType AcquireCacheNexusPixels( - const CacheInfo *magick_restrict cache_info,const MagickOffsetType length, - NexusInfo *nexus_info,ExceptionInfo *exception) + const CacheInfo *magick_restrict cache_info,NexusInfo *nexus_info, + ExceptionInfo *exception) { - if (nexus_info->cache != (Quantum *) NULL) - RelinquishCacheNexusPixels(nexus_info); - if (length != (MagickSizeType) ((size_t) length)) + if (nexus_info->length != (MagickSizeType) ((size_t) nexus_info->length)) return(MagickFalse); if (cache_anonymous_memory <= 0) { + nexus_info->mapped=MagickFalse; nexus_info->cache=(Quantum *) MagickAssumeAligned(AcquireAlignedMemory(1, - (size_t) length)); + (size_t) nexus_info->length)); if (nexus_info->cache != (Quantum *) NULL) - (void) memset(nexus_info->cache,0,(size_t) length); + (void) memset(nexus_info->cache,0,(size_t) nexus_info->length); } - if (nexus_info->cache == (Quantum *) NULL) + else { - nexus_info->cache=(Quantum *) MapBlob(-1,IOMode,0,(size_t) length); - if (nexus_info->cache != (Quantum *) NULL) - nexus_info->mapped=MagickTrue; + nexus_info->mapped=MagickTrue; + nexus_info->cache=(Quantum *) MapBlob(-1,IOMode,0,(size_t) + nexus_info->length); } if (nexus_info->cache == (Quantum *) NULL) { @@ -4991,8 +4987,6 @@ static inline MagickBooleanType AcquireCacheNexusPixels( cache_info->filename); return(MagickFalse); } - nexus_info->length=length; - nexus_info->authentic_pixel_cache=MagickFalse; return(MagickTrue); } @@ -5082,8 +5076,9 @@ static Quantum *SetPixelCacheNexusPixels(const CacheInfo *cache_info, if (cache_info->metacontent_extent != 0) nexus_info->metacontent=(unsigned char *) cache_info->metacontent+ offset*cache_info->metacontent_extent; - nexus_info->authentic_pixel_cache=MagickTrue; PrefetchPixelCacheNexusPixels(nexus_info,mode); + nexus_info->authentic_pixel_cache=IsPixelCacheAuthentic(cache_info, + nexus_info); return(nexus_info->pixels); } } @@ -5095,23 +5090,34 @@ static Quantum *SetPixelCacheNexusPixels(const CacheInfo *cache_info, length+=number_pixels*cache_info->metacontent_extent; if (nexus_info->cache == (Quantum *) NULL) { - status=AcquireCacheNexusPixels(cache_info,length,nexus_info,exception); + nexus_info->length=length; + status=AcquireCacheNexusPixels(cache_info,nexus_info,exception); if (status == MagickFalse) - return((Quantum *) NULL); + { + nexus_info->length=0; + return((Quantum *) NULL); + } } else if (nexus_info->length < length) { - status=AcquireCacheNexusPixels(cache_info,length,nexus_info,exception); + RelinquishCacheNexusPixels(nexus_info); + nexus_info->length=length; + status=AcquireCacheNexusPixels(cache_info,nexus_info,exception); if (status == MagickFalse) - return((Quantum *) NULL); + { + nexus_info->length=0; + return((Quantum *) NULL); + } } nexus_info->pixels=nexus_info->cache; nexus_info->metacontent=(void *) NULL; if (cache_info->metacontent_extent != 0) nexus_info->metacontent=(void *) (nexus_info->pixels+ - cache_info->number_channels*number_pixels); + (cache_info->number_channels*number_pixels)); PrefetchPixelCacheNexusPixels(nexus_info,mode); + nexus_info->authentic_pixel_cache=IsPixelCacheAuthentic(cache_info, + nexus_info); return(nexus_info->pixels); } @@ -5760,7 +5766,7 @@ static MagickBooleanType WritePixelCachePixels( length=extent; rows=1UL; } - q=cache_info->pixels+cache_info->number_channels*offset; + q=cache_info->pixels+offset*cache_info->number_channels; for (y=0; y < (ssize_t) rows; y++) { (void) memcpy(q,p,(size_t) length); diff --git a/MagickCore/memory.c b/MagickCore/memory.c index 6181367b5..52edf10c3 100644 --- a/MagickCore/memory.c +++ b/MagickCore/memory.c @@ -243,7 +243,6 @@ MagickExport void *AcquireAlignedMemory(const size_t count,const size_t quantum) { #define AlignedExtent(size,alignment) \ (((size)+((alignment)-1)) & ~((alignment)-1)) -#define AlignedPowerOf2(x) ((((x) - 1) & (x)) == 0) size_t alignment, @@ -256,9 +255,11 @@ MagickExport void *AcquireAlignedMemory(const size_t count,const size_t quantum) if (HeapOverflowSanityCheck(count,quantum) != MagickFalse) return((void *) NULL); memory=NULL; - alignment=CACHE_LINE_SIZE; size=count*quantum; + alignment=CACHE_LINE_SIZE; extent=AlignedExtent(size,alignment); + if ((size == 0) || (extent < size)) + return((void *) NULL); #if defined(MAGICKCORE_HAVE_POSIX_MEMALIGN) if (posix_memalign(&memory,alignment,extent) != 0) memory=NULL; @@ -269,23 +270,15 @@ MagickExport void *AcquireAlignedMemory(const size_t count,const size_t quantum) void *p; - if ((alignment == 0) || (alignment % sizeof (void *) != 0) || - (AlignedPowerOf2(alignment/sizeof (void *)) == 0)) - { - errno=EINVAL; - return((void *) NULL); - } - if (size > (SIZE_MAX-alignment-sizeof(void *)-1)) - { - errno=ENOMEM; - return((void *) NULL); - } extent=(size+alignment-1)+sizeof(void *); - p=malloc(extent); - if (p != NULL) + if (extent > size) { - memory=(void *) AlignedExtent((size_t) p+sizeof(void *),alignment); - *((void **) memory-1)=p; + p=malloc(extent); + if (p != NULL) + { + memory=(void *) AlignedExtent((size_t) p+sizeof(void *),alignment); + *((void **) memory-1)=p; + } } } #endif -- 2.40.0