From: cristy Date: Sun, 21 Dec 2014 23:17:23 +0000 (+0000) Subject: (no commit message) X-Git-Tag: 7.0.1-0~1581 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=ba158d982cdde8dd13751fd91923a96330fde0fa;p=imagemagick --- diff --git a/MagickCore/cache.c b/MagickCore/cache.c index d23c53f20..58d243f1b 100644 --- a/MagickCore/cache.c +++ b/MagickCore/cache.c @@ -3297,6 +3297,10 @@ static MagickBooleanType OpenPixelCache(Image *image,const MapMode mode, (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); if ((image->columns == 0) || (image->rows == 0)) ThrowBinaryException(CacheError,"NoPixelsDefinedInCache",image->filename); + if ((AcquireMagickResource(WidthResource,image->columns) == MagickFalse) || + (AcquireMagickResource(HeightResource,image->rows) == MagickFalse)) + ThrowBinaryException(ResourceLimitError,"PixelCacheAllocationFailed", + image->filename); cache_info=(CacheInfo *) image->cache; assert(cache_info->signature == MagickSignature); source_info=(*cache_info); diff --git a/MagickCore/option.c b/MagickCore/option.c index 7b077e42e..efc0dfa88 100644 --- a/MagickCore/option.c +++ b/MagickCore/option.c @@ -1601,10 +1601,12 @@ static const OptionInfo { "Area", AreaResource, UndefinedOptionFlag, MagickFalse }, { "Disk", DiskResource, UndefinedOptionFlag, MagickFalse }, { "File", FileResource, UndefinedOptionFlag, MagickFalse }, + { "Height", HeightResource, UndefinedOptionFlag, MagickFalse }, { "Map", MapResource, UndefinedOptionFlag, MagickFalse }, { "Memory", MemoryResource, UndefinedOptionFlag, MagickFalse }, { "Thread", ThreadResource, UndefinedOptionFlag, MagickFalse }, { "Time", TimeResource, UndefinedOptionFlag, MagickFalse }, + { "Width", WidthResource, UndefinedOptionFlag, MagickFalse }, { (char *) NULL, UndefinedResource, UndefinedOptionFlag, MagickFalse } }, SparseColorOptions[] = diff --git a/MagickCore/resource.c b/MagickCore/resource.c index e383d30e2..899565d00 100644 --- a/MagickCore/resource.c +++ b/MagickCore/resource.c @@ -71,6 +71,8 @@ typedef struct _ResourceInfo { MagickOffsetType + width, + height, area, memory, map, @@ -81,6 +83,8 @@ typedef struct _ResourceInfo time; MagickSizeType + width_limit, + height_limit, area_limit, memory_limit, map_limit, @@ -100,6 +104,8 @@ static RandomInfo static ResourceInfo resource_info = { + MagickULLConstant(0), /* initial width */ + MagickULLConstant(0), /* initial height */ MagickULLConstant(0), /* initial area */ MagickULLConstant(0), /* initial memory */ MagickULLConstant(0), /* initial map */ @@ -108,6 +114,8 @@ static ResourceInfo MagickULLConstant(0), /* initial thread */ MagickULLConstant(0), /* initial throttle */ MagickULLConstant(0), /* initial time */ + MagickULLConstant(10000000), /* width limit */ + MagickULLConstant(10000000), /* height limit */ MagickULLConstant(3072)*1024*1024, /* area limit */ MagickULLConstant(1536)*1024*1024, /* memory limit */ MagickULLConstant(3072)*1024*1024, /* map limit */ @@ -235,6 +243,18 @@ MagickExport MagickBooleanType AcquireMagickResource(const ResourceType type, MagickFalse,resource_limit); break; } + case HeightResource: + { + resource_info.area=(MagickOffsetType) size; + limit=resource_info.height_limit; + status=(resource_info.area_limit == MagickResourceInfinity) || + (size < limit) ? MagickTrue : MagickFalse; + (void) FormatMagickSize((MagickSizeType) resource_info.height,MagickFalse, + resource_current); + (void) FormatMagickSize(resource_info.height_limit,MagickFalse, + resource_limit); + break; + } case ThreadResource: { limit=resource_info.thread_limit; @@ -272,6 +292,18 @@ MagickExport MagickBooleanType AcquireMagickResource(const ResourceType type, MagickFalse,resource_limit); break; } + case WidthResource: + { + resource_info.area=(MagickOffsetType) size; + limit=resource_info.width_limit; + status=(resource_info.area_limit == MagickResourceInfinity) || + (size < limit) ? MagickTrue : MagickFalse; + (void) FormatMagickSize((MagickSizeType) resource_info.width,MagickFalse, + resource_current); + (void) FormatMagickSize(resource_info.width_limit,MagickFalse, + resource_limit); + break; + } default: break; } @@ -552,6 +584,16 @@ MagickExport MagickSizeType GetMagickResource(const ResourceType type) LockSemaphoreInfo(resource_semaphore); switch (type) { + case WidthResource: + { + resource=(MagickSizeType) resource_info.width; + break; + } + case HeightResource: + { + resource=(MagickSizeType) resource_info.height; + break; + } case AreaResource: { resource=(MagickSizeType) resource_info.area; @@ -632,6 +674,16 @@ MagickExport MagickSizeType GetMagickResourceLimit(const ResourceType type) LockSemaphoreInfo(resource_semaphore); switch (type) { + case WidthResource: + { + resource=resource_info.width_limit; + break; + } + case HeightResource: + { + resource=resource_info.height_limit; + break; + } case AreaResource: { resource=resource_info.area_limit; @@ -710,15 +762,19 @@ MagickExport MagickBooleanType ListMagickResourceInfo(FILE *file, char area_limit[MaxTextExtent], disk_limit[MaxTextExtent], + height_limit[MaxTextExtent], map_limit[MaxTextExtent], memory_limit[MaxTextExtent], - time_limit[MaxTextExtent]; + time_limit[MaxTextExtent], + width_limit[MaxTextExtent]; if (file == (const FILE *) NULL) file=stdout; if (resource_semaphore == (SemaphoreInfo *) NULL) ActivateSemaphoreInfo(&resource_semaphore); LockSemaphoreInfo(resource_semaphore); + (void) FormatMagickSize(resource_info.width_limit,MagickFalse,width_limit); + (void) FormatMagickSize(resource_info.height_limit,MagickFalse,height_limit); (void) FormatMagickSize(resource_info.area_limit,MagickFalse,area_limit); (void) FormatMagickSize(resource_info.memory_limit,MagickTrue,memory_limit); (void) FormatMagickSize(resource_info.map_limit,MagickTrue,map_limit); @@ -729,16 +785,20 @@ MagickExport MagickBooleanType ListMagickResourceInfo(FILE *file, if (resource_info.time_limit != MagickResourceInfinity) (void) FormatLocaleString(time_limit,MaxTextExtent,"%.20g",(double) ((MagickOffsetType) resource_info.time_limit)); - (void) FormatLocaleFile(file," File Area Memory Map" - " Disk Thread Throttle Time\n"); - (void) FormatLocaleFile(file, - "--------------------------------------------------------" - "------------------------\n"); - (void) FormatLocaleFile(file,"%6g %10s %10s %10s %10s %8g %8g %10s\n", - (double) ((MagickOffsetType) resource_info.file_limit),area_limit, - memory_limit,map_limit,disk_limit,(double) ((MagickOffsetType) - resource_info.thread_limit),(double) ((MagickOffsetType) - resource_info.throttle_limit),time_limit); + (void) FormatLocaleFile(file,"Resource limits:\n"); + (void) FormatLocaleFile(file," Width: %s\n",width_limit); + (void) FormatLocaleFile(file," Height: %s\n",heigth_limit); + (void) FormatLocaleFile(file," Area: %s\n",area_limit); + (void) FormatLocaleFile(file," Memory: %s\n",memory_limit); + (void) FormatLocaleFile(file," Map: %s\n",map_limit); + (void) FormatLocaleFile(file," Disk: %s\n",disk_limit); + (void) FormatLocaleFile(file," File: %.20g\n",(double) ((MagickOffsetType) + resource_info.file_limit)); + (void) FormatLocaleFile(file," Thread: %.20g\n",(double) ((MagickOffsetType) + resource_info.thread_limit)); + (void) FormatLocaleFile(file," Throttle: %.20g\n",(double) + ((MagickOffsetType) resource_info.throttle_limit)); + (void) FormatLocaleFile(file," Time: %s\n",time_limit); (void) fflush(file); UnlockSemaphoreInfo(resource_semaphore); return(MagickTrue); @@ -783,6 +843,24 @@ MagickExport void RelinquishMagickResource(const ResourceType type, LockSemaphoreInfo(resource_semaphore); switch (type) { + case WidthResource: + { + resource_info.width=(MagickOffsetType) size; + (void) FormatMagickSize((MagickSizeType) resource_info.width,MagickFalse, + resource_current); + (void) FormatMagickSize(resource_info.width_limit,MagickFalse, + resource_limit); + break; + } + case HeightResource: + { + resource_info.width=(MagickOffsetType) size; + (void) FormatMagickSize((MagickSizeType) resource_info.width,MagickFalse, + resource_current); + (void) FormatMagickSize(resource_info.width_limit,MagickFalse, + resource_limit); + break; + } case AreaResource: { resource_info.area=(MagickOffsetType) size; @@ -971,6 +1049,20 @@ MagickPrivate MagickBooleanType ResourceComponentGenesis(void) memory=PixelCacheThreshold; #endif (void) SetMagickResourceLimit(AreaResource,2*memory); + limit=GetEnvironmentValue("MAGICK_WIDTH_LIMIT"); + if (limit != (char *) NULL) + { + (void) SetMagickResourceLimit(WidthResource,StringToSizeType(limit, + 100.0)); + limit=DestroyString(limit); + } + limit=GetEnvironmentValue("MAGICK_HEIGHT_LIMIT"); + if (limit != (char *) NULL) + { + (void) SetMagickResourceLimit(HeightResource,StringToSizeType(limit, + 100.0)); + limit=DestroyString(limit); + } limit=GetEnvironmentValue("MAGICK_AREA_LIMIT"); if (limit != (char *) NULL) { @@ -1131,6 +1223,24 @@ MagickExport MagickBooleanType SetMagickResourceLimit(const ResourceType type, value=(char *) NULL; switch (type) { + case WidthResource: + { + resource_info.width_limit=limit; + value=GetPolicyValue("width"); + if (value != (char *) NULL) + resource_info.width_limit=MagickMin(limit,StringToSizeType(value, + 100.0)); + break; + } + case HeightResource: + { + resource_info.height_limit=limit; + value=GetPolicyValue("height"); + if (value != (char *) NULL) + resource_info.height_limit=MagickMin(limit,StringToSizeType(value, + 100.0)); + break; + } case AreaResource: { resource_info.area_limit=limit; diff --git a/MagickCore/resource_.h b/MagickCore/resource_.h index f886c6bb4..cb55c2db5 100644 --- a/MagickCore/resource_.h +++ b/MagickCore/resource_.h @@ -28,11 +28,13 @@ typedef enum AreaResource, DiskResource, FileResource, + HeightResource, MapResource, MemoryResource, ThreadResource, ThrottleResource, - TimeResource + TimeResource, + WidthResource } ResourceType; #define MagickResourceInfinity MagickULLConstant(~0) diff --git a/config/policy.xml b/config/policy.xml index 7a35d2e22..5cf6f1451 100644 --- a/config/policy.xml +++ b/config/policy.xml @@ -48,6 +48,8 @@ + +