]> granicus.if.org Git - imagemagick/commitdiff
(no commit message)
authorcristy <urban-warrior@git.imagemagick.org>
Sun, 21 Dec 2014 23:17:23 +0000 (23:17 +0000)
committercristy <urban-warrior@git.imagemagick.org>
Sun, 21 Dec 2014 23:17:23 +0000 (23:17 +0000)
MagickCore/cache.c
MagickCore/option.c
MagickCore/resource.c
MagickCore/resource_.h
config/policy.xml

index d23c53f209a8035ee3ec47359e3d84436762fb6d..58d243f1b5ea639a954406f61f3967e68589da72 100644 (file)
@@ -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);
index 7b077e42e334e209e126fa1157bd5b97a51045a3..efc0dfa88ee5fe36b1ab01235a9f13e94830073c 100644 (file)
@@ -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[] =
index e383d30e263b7204fcc067ffbeb1e7dd8e1b8dc4..899565d00b2bf4e1ea38d7a2887db6179013e60b 100644 (file)
@@ -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;
index f886c6bb4f58593b2923c77af93ad35fa17e43a0..cb55c2db51507426aa4bfc4746e870083699bc8e 100644 (file)
@@ -28,11 +28,13 @@ typedef enum
   AreaResource,
   DiskResource,
   FileResource,
+  HeightResource,
   MapResource,
   MemoryResource,
   ThreadResource,
   ThrottleResource,
-  TimeResource
+  TimeResource,
+  WidthResource
 } ResourceType;
 
 #define MagickResourceInfinity  MagickULLConstant(~0)
index 7a35d2e22e36a60ac42f713235047b3379ff95c8..5cf6f145189c11bb9890251a28e3949b176e89f8 100644 (file)
@@ -48,6 +48,8 @@
   <!-- <policy domain="resource" name="temporary-path" value="/tmp"/> -->
   <!-- <policy domain="resource" name="memory" value="2GiB"/> -->
   <!-- <policy domain="resource" name="map" value="4GiB"/> -->
+  <!-- <policy domain="resource" name="width" value="1GB"/> -->
+  <!-- <policy domain="resource" name="height" value="1GB"/> -->
   <!-- <policy domain="resource" name="area" value="1GB"/> -->
   <!-- <policy domain="resource" name="disk" value="16EB"/> -->
   <!-- <policy domain="resource" name="file" value="768"/> -->