]> granicus.if.org Git - imagemagick/blobdiff - MagickCore/resource.c
Handle short months in png_write_iTIME()
[imagemagick] / MagickCore / resource.c
index 16c1979913bb8825d8639356f086634a0139d1d4..7b00c1b741d9ddf41b60c5aff77973f709a7f1ac 100644 (file)
 %                               September 2002                                %
 %                                                                             %
 %                                                                             %
-%  Copyright 1999-2015 ImageMagick Studio LLC, a non-profit organization      %
+%  Copyright 1999-2017 ImageMagick Studio LLC, a non-profit organization      %
 %  dedicated to making software imaging solutions freely available.           %
 %                                                                             %
 %  You may not use this file except in compliance with the License.  You may  %
 %  obtain a copy of the License at                                            %
 %                                                                             %
-%    http://www.imagemagick.org/script/license.php                            %
+%    https://www.imagemagick.org/script/license.php                           %
 %                                                                             %
 %  Unless required by applicable law or agreed to in writing, software        %
 %  distributed under the License is distributed on an "AS IS" BASIS,          %
 */
 #include "MagickCore/studio.h"
 #include "MagickCore/cache.h"
+#include "MagickCore/cache-private.h"
 #include "MagickCore/configure.h"
 #include "MagickCore/exception.h"
 #include "MagickCore/exception-private.h"
-#include "MagickCore/hashmap.h"
+#include "MagickCore/linked-list.h"
 #include "MagickCore/log.h"
 #include "MagickCore/image.h"
 #include "MagickCore/image-private.h"
 #include "MagickCore/utility.h"
 #include "MagickCore/utility-private.h"
 \f
+/*
+  Define declarations.
+*/
+#define MagickPathTemplate "XXXXXXXXXXXX"
+\f
 /*
   Typedef declarations.
 */
@@ -164,9 +170,9 @@ MagickExport MagickBooleanType AcquireMagickResource(const ResourceType type,
   const MagickSizeType size)
 {
   char
-    resource_current[MaxTextExtent],
-    resource_limit[MaxTextExtent],
-    resource_request[MaxTextExtent];
+    resource_current[MagickFormatExtent],
+    resource_limit[MagickFormatExtent],
+    resource_request[MagickFormatExtent];
 
   MagickBooleanType
     status;
@@ -175,7 +181,8 @@ MagickExport MagickBooleanType AcquireMagickResource(const ResourceType type,
     limit;
 
   status=MagickFalse;
-  (void) FormatMagickSize(size,MagickFalse,"B",resource_request);
+  (void) FormatMagickSize(size,MagickFalse,"B",MagickFormatExtent,
+    resource_request);
   if (resource_semaphore == (SemaphoreInfo *) NULL)
     ActivateSemaphoreInfo(&resource_semaphore);
   LockSemaphoreInfo(resource_semaphore);
@@ -188,9 +195,9 @@ MagickExport MagickBooleanType AcquireMagickResource(const ResourceType type,
       status=(resource_info.area_limit == MagickResourceInfinity) ||
         (size < limit) ? MagickTrue : MagickFalse;
       (void) FormatMagickSize((MagickSizeType) resource_info.area,MagickFalse,
-        "B",resource_current);
-      (void) FormatMagickSize(resource_info.area_limit,MagickFalse,
-        "B",resource_limit);
+        "P",MagickFormatExtent,resource_current);
+      (void) FormatMagickSize(resource_info.area_limit,MagickFalse,"P",
+        MagickFormatExtent,resource_limit);
       break;
     }
     case MemoryResource:
@@ -201,9 +208,9 @@ MagickExport MagickBooleanType AcquireMagickResource(const ResourceType type,
         ((MagickSizeType) resource_info.memory < limit) ? MagickTrue :
         MagickFalse;
       (void) FormatMagickSize((MagickSizeType) resource_info.memory,MagickTrue,
-        "B",resource_current);
-      (void) FormatMagickSize(resource_info.memory_limit,MagickTrue,
-        "B",resource_limit);
+        "B",MagickFormatExtent,resource_current);
+      (void) FormatMagickSize(resource_info.memory_limit,MagickTrue,"B",
+        MagickFormatExtent,resource_limit);
       break;
     }
     case MapResource:
@@ -213,9 +220,9 @@ MagickExport MagickBooleanType AcquireMagickResource(const ResourceType type,
       status=(resource_info.map_limit == MagickResourceInfinity) ||
         ((MagickSizeType) resource_info.map < limit) ? MagickTrue : MagickFalse;
       (void) FormatMagickSize((MagickSizeType) resource_info.map,MagickTrue,
-        "B",resource_current);
-      (void) FormatMagickSize(resource_info.map_limit,MagickTrue,
-        "B",resource_limit);
+        "B",MagickFormatExtent,resource_current);
+      (void) FormatMagickSize(resource_info.map_limit,MagickTrue,"B",
+        MagickFormatExtent,resource_limit);
       break;
     }
     case DiskResource:
@@ -226,9 +233,9 @@ MagickExport MagickBooleanType AcquireMagickResource(const ResourceType type,
         ((MagickSizeType) resource_info.disk < limit) ? MagickTrue :
         MagickFalse;
       (void) FormatMagickSize((MagickSizeType) resource_info.disk,MagickTrue,
-        "B",resource_current);
-      (void) FormatMagickSize(resource_info.disk_limit,MagickTrue,
-        "B",resource_limit);
+        "B",MagickFormatExtent,resource_current);
+      (void) FormatMagickSize(resource_info.disk_limit,MagickTrue,"B",
+        MagickFormatExtent,resource_limit);
       break;
     }
     case FileResource:
@@ -239,9 +246,9 @@ MagickExport MagickBooleanType AcquireMagickResource(const ResourceType type,
         ((MagickSizeType) resource_info.file < limit) ?
         MagickTrue : MagickFalse;
       (void) FormatMagickSize((MagickSizeType) resource_info.file,MagickFalse,
-        "B",resource_current);
+        "B",MagickFormatExtent,resource_current);
       (void) FormatMagickSize((MagickSizeType) resource_info.file_limit,
-        MagickFalse,"B",resource_limit);
+        MagickFalse,"B",MagickFormatExtent,resource_limit);
       break;
     }
     case HeightResource:
@@ -251,9 +258,9 @@ MagickExport MagickBooleanType AcquireMagickResource(const ResourceType type,
       status=(resource_info.area_limit == MagickResourceInfinity) ||
         (size < limit) ? MagickTrue : MagickFalse;
       (void) FormatMagickSize((MagickSizeType) resource_info.height,MagickFalse,
-        "P",resource_current);
-      (void) FormatMagickSize(resource_info.height_limit,MagickFalse,
-        "P",resource_limit);
+        "P",MagickFormatExtent,resource_current);
+      (void) FormatMagickSize(resource_info.height_limit,MagickFalse,"P",
+        MagickFormatExtent,resource_limit);
       break;
     }
     case ThreadResource:
@@ -263,9 +270,9 @@ MagickExport MagickBooleanType AcquireMagickResource(const ResourceType type,
         ((MagickSizeType) resource_info.thread < limit) ?
         MagickTrue : MagickFalse;
       (void) FormatMagickSize((MagickSizeType) resource_info.thread,MagickFalse,
-        "B",resource_current);
+        "B",MagickFormatExtent,resource_current);
       (void) FormatMagickSize((MagickSizeType) resource_info.thread_limit,
-        MagickFalse,"B",resource_limit);
+        MagickFalse,"B",MagickFormatExtent,resource_limit);
       break;
     }
     case ThrottleResource:
@@ -275,9 +282,9 @@ MagickExport MagickBooleanType AcquireMagickResource(const ResourceType type,
         ((MagickSizeType) resource_info.throttle < limit) ?
         MagickTrue : MagickFalse;
       (void) FormatMagickSize((MagickSizeType) resource_info.throttle,
-        MagickFalse,"B",resource_current);
+        MagickFalse,"B",MagickFormatExtent,resource_current);
       (void) FormatMagickSize((MagickSizeType) resource_info.throttle_limit,
-        MagickFalse,"B",resource_limit);
+        MagickFalse,"B",MagickFormatExtent,resource_limit);
       break;
     }
     case TimeResource:
@@ -288,9 +295,9 @@ MagickExport MagickBooleanType AcquireMagickResource(const ResourceType type,
         ((MagickSizeType) resource_info.time < limit) ?
         MagickTrue : MagickFalse;
       (void) FormatMagickSize((MagickSizeType) resource_info.time,MagickFalse,
-        "B",resource_current);
+        "B",MagickFormatExtent,resource_current);
       (void) FormatMagickSize((MagickSizeType) resource_info.time_limit,
-        MagickFalse,"B",resource_limit);
+        MagickFalse,"B",MagickFormatExtent,resource_limit);
       break;
     }
     case WidthResource:
@@ -300,9 +307,9 @@ MagickExport MagickBooleanType AcquireMagickResource(const ResourceType type,
       status=(resource_info.area_limit == MagickResourceInfinity) ||
         (size < limit) ? MagickTrue : MagickFalse;
       (void) FormatMagickSize((MagickSizeType) resource_info.width,MagickFalse,
-        "P",resource_current);
-      (void) FormatMagickSize(resource_info.width_limit,MagickFalse,
-        "P",resource_limit);
+        "P",MagickFormatExtent,resource_current);
+      (void) FormatMagickSize(resource_info.width_limit,MagickFalse,"P",
+        MagickFormatExtent,resource_limit);
       break;
     }
     default:
@@ -401,8 +408,8 @@ MagickExport MagickBooleanType GetPathTemplate(char *path)
   struct stat
     attributes;
 
-  (void) FormatLocaleString(path,MaxTextExtent,"magick-%.20gXXXXXXXXXXXX",
-    (double) getpid());
+  (void) FormatLocaleString(path,MagickPathExtent,"magick-%.20g"
+    MagickPathTemplate,(double) getpid());
   exception=AcquireExceptionInfo();
   directory=(char *) GetImageRegistry(StringRegistryType,"temporary-path",
     exception);
@@ -413,7 +420,7 @@ MagickExport MagickBooleanType GetPathTemplate(char *path)
     directory=GetEnvironmentValue("MAGICK_TMPDIR");
   if (directory == (char *) NULL)
     directory=GetEnvironmentValue("TMPDIR");
-#if defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__OS2__)
+#if defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__OS2__) || defined(__CYGWIN__)
   if (directory == (char *) NULL)
     directory=GetEnvironmentValue("TMP");
   if (directory == (char *) NULL)
@@ -429,10 +436,13 @@ MagickExport MagickBooleanType GetPathTemplate(char *path)
 #endif
   if (directory == (char *) NULL)
     return(MagickTrue);
-  value=GetPolicyValue("temporary-path");
+  value=GetPolicyValue("resource:temporary-path");
   if (value != (char *) NULL)
-    (void) CloneString(&directory,value);
-  if (strlen(directory) > (MaxTextExtent-25))
+    {
+      (void) CloneString(&directory,value);
+      value=DestroyString(value);
+    }
+  if (strlen(directory) > (MagickPathExtent-25))
     {
       directory=DestroyString(directory);
       return(MagickFalse);
@@ -444,11 +454,11 @@ MagickExport MagickBooleanType GetPathTemplate(char *path)
       return(MagickFalse);
     }
   if (directory[strlen(directory)-1] == *DirectorySeparator)
-    (void) FormatLocaleString(path,MaxTextExtent,"%smagick-%.20gXXXXXXXXXXXX",
-      directory,(double) getpid());
+    (void) FormatLocaleString(path,MagickPathExtent,
+      "%smagick-%.20g" MagickPathTemplate,directory,(double) getpid());
   else
-    (void) FormatLocaleString(path,MaxTextExtent,
-      "%s%smagick-%.20gXXXXXXXXXXXX",directory,DirectorySeparator,
+    (void) FormatLocaleString(path,MagickPathExtent,
+      "%s%smagick-%.20g" MagickPathTemplate,directory,DirectorySeparator,
       (double) getpid());
   directory=DestroyString(directory);
 #if defined(MAGICKCORE_WINDOWS_SUPPORT)
@@ -514,7 +524,7 @@ MagickExport int AcquireUniqueFileResource(char *path)
     */
     (void) GetPathTemplate(path);
     key=GetRandomKey(random_info,6);
-    p=path+strlen(path)-12;
+    p=path+strlen(path)-strlen(MagickPathTemplate);
     datum=GetStringInfoDatum(key);
     for (i=0; i < (ssize_t) GetStringInfoLength(key); i++)
     {
@@ -526,15 +536,17 @@ MagickExport int AcquireUniqueFileResource(char *path)
     file=mkstemp(path);
     if (file != -1)
       {
+#if defined(MAGICKCORE_HAVE_FCHMOD)
         (void) fchmod(file,0600);
+#endif
 #if defined(__OS2__)
         setmode(file,O_BINARY);
 #endif
         break;
       }
 #endif
-    key=GetRandomKey(random_info,12);
-    p=path+strlen(path)-12;
+    key=GetRandomKey(random_info,strlen(MagickPathTemplate));
+    p=path+strlen(path)-strlen(MagickPathTemplate);
     datum=GetStringInfoDatum(key);
     for (i=0; i < (ssize_t) GetStringInfoLength(key); i++)
     {
@@ -769,13 +781,15 @@ MagickExport MagickBooleanType ListMagickResourceInfo(FILE *file,
   ExceptionInfo *magick_unused(exception))
 {
   char
-    area_limit[MaxTextExtent],
-    disk_limit[MaxTextExtent],
-    height_limit[MaxTextExtent],
-    map_limit[MaxTextExtent],
-    memory_limit[MaxTextExtent],
-    time_limit[MaxTextExtent],
-    width_limit[MaxTextExtent];
+    area_limit[MagickFormatExtent],
+    disk_limit[MagickFormatExtent],
+    height_limit[MagickFormatExtent],
+    map_limit[MagickFormatExtent],
+    memory_limit[MagickFormatExtent],
+    time_limit[MagickFormatExtent],
+    width_limit[MagickFormatExtent];
+
+  magick_unreferenced(exception);
 
   if (file == (const FILE *) NULL)
     file=stdout;
@@ -783,19 +797,22 @@ MagickExport MagickBooleanType ListMagickResourceInfo(FILE *file,
     ActivateSemaphoreInfo(&resource_semaphore);
   LockSemaphoreInfo(resource_semaphore);
   (void) FormatMagickSize(resource_info.width_limit,MagickFalse,"P",
-    width_limit);
+    MagickFormatExtent,width_limit);
   (void) FormatMagickSize(resource_info.height_limit,MagickFalse,"P",
-    height_limit);
-  (void) FormatMagickSize(resource_info.area_limit,MagickFalse,"B",area_limit);
+    MagickFormatExtent,height_limit);
+  (void) FormatMagickSize(resource_info.area_limit,MagickFalse,"P",
+    MagickFormatExtent,area_limit);
   (void) FormatMagickSize(resource_info.memory_limit,MagickTrue,"B",
-    memory_limit);
-  (void) FormatMagickSize(resource_info.map_limit,MagickTrue,"B",map_limit);
-  (void) CopyMagickString(disk_limit,"unlimited",MaxTextExtent);
+    MagickFormatExtent,memory_limit);
+  (void) FormatMagickSize(resource_info.map_limit,MagickTrue,"B",
+    MagickFormatExtent,map_limit);
+  (void) CopyMagickString(disk_limit,"unlimited",MagickFormatExtent);
   if (resource_info.disk_limit != MagickResourceInfinity)
-    (void) FormatMagickSize(resource_info.disk_limit,MagickTrue,"B",disk_limit);
-  (void) CopyMagickString(time_limit,"unlimited",MaxTextExtent);
+    (void) FormatMagickSize(resource_info.disk_limit,MagickTrue,"B",
+      MagickFormatExtent,disk_limit);
+  (void) CopyMagickString(time_limit,"unlimited",MagickFormatExtent);
   if (resource_info.time_limit != MagickResourceInfinity)
-    (void) FormatLocaleString(time_limit,MaxTextExtent,"%.20g",(double)
+    (void) FormatLocaleString(time_limit,MagickFormatExtent,"%.20g",(double)
       ((MagickOffsetType) resource_info.time_limit));
   (void) FormatLocaleFile(file,"Resource limits:\n");
   (void) FormatLocaleFile(file,"  Width: %s\n",width_limit);
@@ -845,11 +862,12 @@ MagickExport void RelinquishMagickResource(const ResourceType type,
   const MagickSizeType size)
 {
   char
-    resource_current[MaxTextExtent],
-    resource_limit[MaxTextExtent],
-    resource_request[MaxTextExtent];
+    resource_current[MagickFormatExtent],
+    resource_limit[MagickFormatExtent],
+    resource_request[MagickFormatExtent];
 
-  (void) FormatMagickSize(size,MagickFalse,"B",resource_request);
+  (void) FormatMagickSize(size,MagickFalse,"B",MagickFormatExtent,
+    resource_request);
   if (resource_semaphore == (SemaphoreInfo *) NULL)
                ActivateSemaphoreInfo(&resource_semaphore);
   LockSemaphoreInfo(resource_semaphore);
@@ -859,88 +877,88 @@ MagickExport void RelinquishMagickResource(const ResourceType type,
     {
       resource_info.width=(MagickOffsetType) size;
       (void) FormatMagickSize((MagickSizeType) resource_info.width,MagickFalse,
-        "P",resource_current);
-      (void) FormatMagickSize(resource_info.width_limit,MagickFalse,
-        "P",resource_limit);
+        "P",MagickFormatExtent,resource_current);
+      (void) FormatMagickSize(resource_info.width_limit,MagickFalse,"P",
+        MagickFormatExtent,resource_limit);
       break;
     }
     case HeightResource:
     {
-      resource_info.width=(MagickOffsetType) size;
-      (void) FormatMagickSize((MagickSizeType) resource_info.width,MagickFalse,
-        "P",resource_current);
-      (void) FormatMagickSize(resource_info.width_limit,MagickFalse,
-        "P",resource_limit);
+      resource_info.height=(MagickOffsetType) size;
+      (void) FormatMagickSize((MagickSizeType) resource_info.height,MagickFalse,
+        "P",MagickFormatExtent,resource_current);
+      (void) FormatMagickSize(resource_info.height_limit,MagickFalse,"P",
+        MagickFormatExtent,resource_limit);
       break;
     }
     case AreaResource:
     {
       resource_info.area=(MagickOffsetType) size;
       (void) FormatMagickSize((MagickSizeType) resource_info.area,MagickFalse,
-        "B",resource_current);
-      (void) FormatMagickSize(resource_info.area_limit,MagickFalse,
-        "B",resource_limit);
+        "B",MagickFormatExtent,resource_current);
+      (void) FormatMagickSize(resource_info.area_limit,MagickFalse,"B",
+        MagickFormatExtent,resource_limit);
       break;
     }
     case MemoryResource:
     {
       resource_info.memory-=size;
       (void) FormatMagickSize((MagickSizeType) resource_info.memory,
-        MagickTrue,"B",resource_current);
-      (void) FormatMagickSize(resource_info.memory_limit,MagickTrue,
-        "B",resource_limit);
+        MagickTrue,"B",MagickFormatExtent,resource_current);
+      (void) FormatMagickSize(resource_info.memory_limit,MagickTrue,"B",
+        MagickFormatExtent,resource_limit);
       break;
     }
     case MapResource:
     {
       resource_info.map-=size;
       (void) FormatMagickSize((MagickSizeType) resource_info.map,MagickTrue,
-        "B",resource_current);
-      (void) FormatMagickSize(resource_info.map_limit,MagickTrue,
-        "B",resource_limit);
+        "B",MagickFormatExtent,resource_current);
+      (void) FormatMagickSize(resource_info.map_limit,MagickTrue,"B",
+        MagickFormatExtent,resource_limit);
       break;
     }
     case DiskResource:
     {
       resource_info.disk-=size;
       (void) FormatMagickSize((MagickSizeType) resource_info.disk,MagickTrue,
-        "B",resource_current);
-      (void) FormatMagickSize(resource_info.disk_limit,MagickTrue,
-        "B",resource_limit);
+        "B",MagickFormatExtent,resource_current);
+      (void) FormatMagickSize(resource_info.disk_limit,MagickTrue,"B",
+        MagickFormatExtent,resource_limit);
       break;
     }
     case FileResource:
     {
       resource_info.file-=size;
       (void) FormatMagickSize((MagickSizeType) resource_info.file,MagickFalse,
-        "B",resource_current);
+        "B",MagickFormatExtent,resource_current);
       (void) FormatMagickSize((MagickSizeType) resource_info.file_limit,
-        MagickFalse,"B",resource_limit);
+        MagickFalse,"B",MagickFormatExtent,resource_limit);
       break;
     }
     case ThreadResource:
     {
       (void) FormatMagickSize((MagickSizeType) resource_info.thread,MagickFalse,
-        "B",resource_current);
+        "B",MagickFormatExtent,resource_current);
       (void) FormatMagickSize((MagickSizeType) resource_info.thread_limit,
-        MagickFalse,"B",resource_limit);
+        MagickFalse,"B",MagickFormatExtent,resource_limit);
       break;
     }
     case ThrottleResource:
     {
       (void) FormatMagickSize((MagickSizeType) resource_info.throttle,
-        MagickFalse,"B",resource_current);
+        MagickFalse,"B",MagickFormatExtent,resource_current);
       (void) FormatMagickSize((MagickSizeType) resource_info.throttle_limit,
-        MagickFalse,"B",resource_limit);
+        MagickFalse,"B",MagickFormatExtent,resource_limit);
       break;
     }
     case TimeResource:
     {
       resource_info.time-=size;
       (void) FormatMagickSize((MagickSizeType) resource_info.time,MagickFalse,
-        "B",resource_current);
+        "B",MagickFormatExtent,resource_current);
       (void) FormatMagickSize((MagickSizeType) resource_info.time_limit,
-        MagickFalse,"B",resource_limit);
+        MagickFalse,"B",MagickFormatExtent,resource_limit);
       break;
     }
     default:
@@ -977,7 +995,7 @@ MagickExport void RelinquishMagickResource(const ResourceType type,
 MagickExport MagickBooleanType RelinquishUniqueFileResource(const char *path)
 {
   char
-    cache_path[MaxTextExtent];
+    cache_path[MagickPathExtent];
 
   MagickBooleanType
     status;
@@ -989,9 +1007,9 @@ MagickExport MagickBooleanType RelinquishUniqueFileResource(const char *path)
     ActivateSemaphoreInfo(&resource_semaphore);
   LockSemaphoreInfo(resource_semaphore);
   if (temporary_resources != (SplayTreeInfo *) NULL)
-    status=DeleteNodeFromSplayTree(temporary_resources, (const void *) path);
+    status=DeleteNodeFromSplayTree(temporary_resources,(const void *) path);
   UnlockSemaphoreInfo(resource_semaphore);
-  (void) CopyMagickString(cache_path,path,MaxTextExtent);
+  (void) CopyMagickString(cache_path,path,MagickPathExtent);
   AppendImageFormat("cache",cache_path);
   (void) ShredFile(cache_path);
   if (status == MagickFalse)
@@ -1231,7 +1249,7 @@ MagickExport MagickBooleanType SetMagickResourceLimit(const ResourceType type,
     case WidthResource:
     {
       resource_info.width_limit=limit;
-      value=GetPolicyValue("width");
+      value=GetPolicyValue("resource:width");
       if (value != (char *) NULL)
         resource_info.width_limit=MagickMin(limit,StringToSizeType(value,
           100.0));
@@ -1240,7 +1258,7 @@ MagickExport MagickBooleanType SetMagickResourceLimit(const ResourceType type,
     case HeightResource:
     {
       resource_info.height_limit=limit;
-      value=GetPolicyValue("height");
+      value=GetPolicyValue("resource:height");
       if (value != (char *) NULL)
         resource_info.height_limit=MagickMin(limit,StringToSizeType(value,
           100.0));
@@ -1249,7 +1267,7 @@ MagickExport MagickBooleanType SetMagickResourceLimit(const ResourceType type,
     case AreaResource:
     {
       resource_info.area_limit=limit;
-      value=GetPolicyValue("area");
+      value=GetPolicyValue("resource:area");
       if (value != (char *) NULL)
         resource_info.area_limit=MagickMin(limit,StringToSizeType(value,100.0));
       break;
@@ -1257,7 +1275,7 @@ MagickExport MagickBooleanType SetMagickResourceLimit(const ResourceType type,
     case MemoryResource:
     {
       resource_info.memory_limit=limit;
-      value=GetPolicyValue("memory");
+      value=GetPolicyValue("resource:memory");
       if (value != (char *) NULL)
         resource_info.memory_limit=MagickMin(limit,StringToSizeType(value,
           100.0));
@@ -1266,7 +1284,7 @@ MagickExport MagickBooleanType SetMagickResourceLimit(const ResourceType type,
     case MapResource:
     {
       resource_info.map_limit=limit;
-      value=GetPolicyValue("map");
+      value=GetPolicyValue("resource:map");
       if (value != (char *) NULL)
         resource_info.map_limit=MagickMin(limit,StringToSizeType(value,100.0));
       break;
@@ -1274,7 +1292,7 @@ MagickExport MagickBooleanType SetMagickResourceLimit(const ResourceType type,
     case DiskResource:
     {
       resource_info.disk_limit=limit;
-      value=GetPolicyValue("disk");
+      value=GetPolicyValue("resource:disk");
       if (value != (char *) NULL)
         resource_info.disk_limit=MagickMin(limit,StringToSizeType(value,100.0));
       break;
@@ -1282,7 +1300,7 @@ MagickExport MagickBooleanType SetMagickResourceLimit(const ResourceType type,
     case FileResource:
     {
       resource_info.file_limit=limit;
-      value=GetPolicyValue("file");
+      value=GetPolicyValue("resource:file");
       if (value != (char *) NULL)
         resource_info.file_limit=MagickMin(limit,StringToSizeType(value,100.0));
       break;
@@ -1290,33 +1308,33 @@ MagickExport MagickBooleanType SetMagickResourceLimit(const ResourceType type,
     case ThreadResource:
     {
       resource_info.thread_limit=limit;
-      value=GetPolicyValue("thread");
+      value=GetPolicyValue("resource:thread");
       if (value != (char *) NULL)
         resource_info.thread_limit=MagickMin(limit,StringToSizeType(value,
           100.0));
       if (resource_info.thread_limit > GetOpenMPMaximumThreads())
         resource_info.thread_limit=GetOpenMPMaximumThreads();
-      else if (resource_info.thread_limit == 0)
-        resource_info.thread_limit=1;
+      else
+        if (resource_info.thread_limit == 0)
+          resource_info.thread_limit=1;
       break;
     }
     case ThrottleResource:
     {
       resource_info.throttle_limit=limit;
-      value=GetPolicyValue("throttle");
+      value=GetPolicyValue("resource:throttle");
       if (value != (char *) NULL)
-        resource_info.throttle_limit=MagickMin(limit,StringToSizeType(value,
+        resource_info.throttle_limit=MagickMax(limit,StringToSizeType(value,
           100.0));
-      if (resource_info.throttle_limit > GetOpenMPMaximumThreads())
-        resource_info.throttle_limit=GetOpenMPMaximumThreads();
       break;
     }
     case TimeResource:
     {
       resource_info.time_limit=limit;
-      value=GetPolicyValue("time");
+      value=GetPolicyValue("resource:time");
       if (value != (char *) NULL)
         resource_info.time_limit=MagickMin(limit,StringToSizeType(value,100.0));
+      ResetPixelCacheEpoch();
       break;
     }
     default: