From 7eeac389dd01116a929d6cc68be710cf8891d106 Mon Sep 17 00:00:00 2001 From: Dirk Lemstra Date: Sun, 14 Jan 2018 00:15:19 +0100 Subject: [PATCH] Added SetMagickSecurityPolicyValue that can be used to change a security policy value. --- MagickCore/cache-private.h | 1 + MagickCore/cache.c | 23 +++++ MagickCore/magick-private.h | 3 +- MagickCore/magick.c | 29 +++++- MagickCore/memory-private.h | 4 + MagickCore/memory.c | 65 ++++++++++---- MagickCore/policy.c | 172 +++++++++++++++++++++++++++++++++++- MagickCore/policy.h | 4 +- MagickCore/resource.c | 77 ++++++++-------- MagickCore/stream-private.h | 1 + MagickCore/stream.c | 23 +++++ MagickCore/string-private.h | 24 +++++ 12 files changed, 365 insertions(+), 61 deletions(-) diff --git a/MagickCore/cache-private.h b/MagickCore/cache-private.h index 556bb75ba..e7d66c79d 100644 --- a/MagickCore/cache-private.h +++ b/MagickCore/cache-private.h @@ -280,6 +280,7 @@ extern MagickPrivate void ClonePixelCacheMethods(Cache,const Cache), GetPixelCacheTileSize(const Image *,size_t *,size_t *), GetPixelCacheMethods(CacheMethods *), + ResetCacheAnonymousMemory(void), ResetPixelCacheEpoch(void), ResetPixelCacheChannels(Image *), SetPixelCacheMethods(Cache,CacheMethods *); diff --git a/MagickCore/cache.c b/MagickCore/cache.c index b3b96040d..b27850345 100644 --- a/MagickCore/cache.c +++ b/MagickCore/cache.c @@ -4579,6 +4579,29 @@ MagickPrivate void ResetPixelCacheChannels(Image *image) % % % % % % ++ R e s e t C a c h e A n o n y m o u s M e m o r y % +% % +% % +% % +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% +% ResetCacheAnonymousMemory() resets the anonymous_memory value. +% +% The format of the ResetCacheAnonymousMemory method is: +% +% void ResetCacheAnonymousMemory(void) +% +*/ +MagickPrivate void ResetCacheAnonymousMemory(void) +{ + cache_anonymous_memory=0; +} + +/* +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% % +% % +% % + R e s e t P i x e l C a c h e E p o c h % % % % % diff --git a/MagickCore/magick-private.h b/MagickCore/magick-private.h index daec8b350..f1464c02d 100644 --- a/MagickCore/magick-private.h +++ b/MagickCore/magick-private.h @@ -27,7 +27,8 @@ extern MagickPrivate MagickBooleanType MagickComponentGenesis(void); extern MagickPrivate void - MagickComponentTerminus(void); + MagickComponentTerminus(void), + ResetMagickPrecision(void); #if defined(__cplusplus) || defined(c_plusplus) } diff --git a/MagickCore/magick.c b/MagickCore/magick.c index 8b2fd8c27..3c110b2f8 100644 --- a/MagickCore/magick.c +++ b/MagickCore/magick.c @@ -128,6 +128,9 @@ static volatile MagickBooleanType instantiate_magickcore = MagickFalse, magickcore_signal_in_progress = MagickFalse, magick_list_initialized = MagickFalse; + +static int + magick_precision = 0; /* Forward declarations. @@ -1631,6 +1634,29 @@ MagickExport MagickBooleanType RegisterMagickInfo(MagickInfo *magick_info) % % % % % % ++ R e s e t M a g i c k P r e c i s i o n % +% % +% % +% % +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% +% ResetMagickPrecision() resets the magick_precision value. +% +% The format of the ResetMagickPrecision method is: +% +% void ResetMagickPrecision(void) +% +*/ +MagickPrivate void ResetMagickPrecision(void) +{ + magick_precision=0; +} + +/* +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% % +% % +% % % S e t M a g i c k P r e c i s i o n % % % % % @@ -1659,9 +1685,6 @@ MagickExport int SetMagickPrecision(const int precision) { #define MagickPrecision 6 - static int - magick_precision = 0; - (void) LogMagickEvent(TraceEvent,GetMagickModule(),"..."); if (precision > 0) magick_precision=precision; diff --git a/MagickCore/memory-private.h b/MagickCore/memory-private.h index 36eb82623..4c524b0f7 100644 --- a/MagickCore/memory-private.h +++ b/MagickCore/memory-private.h @@ -46,6 +46,10 @@ extern "C" { MagickExport MagickBooleanType HeapOverflowSanityCheck(const size_t,const size_t) magick_alloc_sizes(1,2); +extern MagickPrivate void + ResetMaxMemoryRequest(void), + ResetVirtualAnonymousMemory(void); + static inline void *AcquireCriticalMemory(const size_t size) { register void diff --git a/MagickCore/memory.c b/MagickCore/memory.c index aaa628b50..8a8556ba5 100644 --- a/MagickCore/memory.c +++ b/MagickCore/memory.c @@ -165,6 +165,10 @@ typedef struct _MemoryPool /* Global declarations. */ +static size_t + max_memory_request = 0, + virtual_anonymous_memory = 0; + #if defined _MSC_VER static void* MSCMalloc(size_t size) { @@ -564,17 +568,6 @@ MagickExport void *AcquireQuantumMemory(const size_t count,const size_t quantum) % */ -static inline size_t StringToSizeType(const char *string,const double interval) -{ - double - value; - - value=SiPrefixToDoubleInterval(string,interval); - if (value >= (double) MagickULLConstant(~0)) - return((size_t) MagickULLConstant(~0)); - return((size_t) value); -} - MagickExport MemoryInfo *AcquireVirtualMemory(const size_t count, const size_t quantum) { @@ -587,10 +580,6 @@ MagickExport MemoryInfo *AcquireVirtualMemory(const size_t count, size_t extent; - static size_t - max_memory_request = 0, - virtual_anonymous_memory = 0; - if (HeapOverflowSanityCheck(count,quantum) != MagickFalse) return((MemoryInfo *) NULL); if (max_memory_request == 0) @@ -1172,6 +1161,52 @@ MagickExport void *ResetMagickMemory(void *memory,int byte,const size_t size) % % % % % % ++ R e s e t M a x M e m o r y R e q u e s t % +% % +% % +% % +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% +% ResetMaxMemoryRequest() resets the anonymous_memory value. +% +% The format of the ResetMaxMemoryRequest method is: +% +% void ResetMaxMemoryRequest(void) +% +*/ +MagickPrivate void ResetMaxMemoryRequest(void) +{ + max_memory_request=0; +} + +/* +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% % +% % +% % ++ R e s e t V i r t u a l A n o n y m o u s M e m o r y % +% % +% % +% % +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% +% ResetVirtualAnonymousMemory() resets the anonymous_memory value. +% +% The format of the ResetVirtualAnonymousMemory method is: +% +% void ResetVirtualAnonymousMemory(void) +% +*/ +MagickPrivate void ResetVirtualAnonymousMemory(void) +{ + virtual_anonymous_memory=0; +} + +/* +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% % +% % +% % % R e s i z e M a g i c k M e m o r y % % % % % diff --git a/MagickCore/policy.c b/MagickCore/policy.c index bdc7e998f..3d5fdb646 100644 --- a/MagickCore/policy.c +++ b/MagickCore/policy.c @@ -41,11 +41,13 @@ Include declarations. */ #include "MagickCore/studio.h" +#include "MagickCore/cache-private.h" #include "MagickCore/client.h" #include "MagickCore/configure.h" #include "MagickCore/configure-private.h" #include "MagickCore/exception.h" #include "MagickCore/exception-private.h" +#include "MagickCore/magick-private.h" #include "MagickCore/memory_.h" #include "MagickCore/memory-private.h" #include "MagickCore/monitor.h" @@ -53,9 +55,12 @@ #include "MagickCore/option.h" #include "MagickCore/policy.h" #include "MagickCore/policy-private.h" +#include "MagickCore/resource_.h" #include "MagickCore/resource-private.h" #include "MagickCore/semaphore.h" +#include "MagickCore/stream-private.h" #include "MagickCore/string_.h" +#include "MagickCore/string-private.h" #include "MagickCore/token.h" #include "MagickCore/utility.h" #include "MagickCore/utility-private.h" @@ -494,7 +499,7 @@ MagickExport char **GetPolicyList(const char *pattern, % % A description of each parameter follows: % -% o policy_info: The policy info. +% o name: The name of the policy. % */ MagickExport char *GetPolicyValue(const char *name) @@ -1090,3 +1095,168 @@ MagickExport MagickBooleanType SetMagickSecurityPolicy(const char *policy, return(MagickFalse); return(ResourceComponentGenesis()); } + +/* +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% % +% % +% % +% S e t M a g i c k S e c u r i t y P o l i c y V a l u e % +% % +% % +% % +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% +% SetMagickSecurityPolicyValue() sets the a value in the ImageMagick security +% policy. It returns MagickFalse if the policy cannot be changed or if the +% policy does not parse. +% +% The format of the SetMagickSecurityPolicyValue method is: +% +% MagickBooleanType SetMagickSecurityPolicyValue( +% const PolicyDomain domain,const char *name,const char *value, +% ExceptionInfo *exception) +% +% A description of each parameter follows: +% +% o domain: the domain of the policy (e.g. system, resource). +% +% o name: the name of the policy. +% +% o value: the value to set the policy to. +% +% o exception: return any errors or warnings in this structure. +% +*/ + +static MagickBooleanType SetPolicyValue(const PolicyDomain domain, + const char *name,const char *value) +{ + MagickBooleanType + status; + + register PolicyInfo + *p; + + register char + *q; + + status=MagickTrue; + LockSemaphoreInfo(policy_semaphore); + ResetLinkedListIterator(policy_cache); + p=(PolicyInfo *) GetNextValueInLinkedList(policy_cache); + while (p != (PolicyInfo *) NULL) + { + if ((p->domain == domain) && (LocaleCompare(name,p->name) == 0)) + break; + p=(PolicyInfo *) GetNextValueInLinkedList(policy_cache); + } + if (p != (PolicyInfo *) NULL) + { + if (p->value != (char *) NULL) + p->value=DestroyString(p->value); + } + else + { + p=(PolicyInfo *) AcquireCriticalMemory(sizeof(*p)); + (void) ResetMagickMemory(p,0,sizeof(*p)); + p->exempt=MagickFalse; + p->signature=MagickCoreSignature; + p->name=ConstantString(name); + status=AppendValueToLinkedList(policy_cache,p); + } + p->value=ConstantString(value); + UnlockSemaphoreInfo(policy_semaphore); + if (status == MagickFalse) + p=(PolicyInfo *) RelinquishMagickMemory(p); + return(status); +} + +MagickExport MagickBooleanType SetMagickSecurityPolicyValue( + const PolicyDomain domain,const char *name,const char *value, + ExceptionInfo *exception) +{ + char + *current_value; + + magick_unreferenced(exception); + assert(exception != (ExceptionInfo *) NULL); + if ((name == (const char *) NULL) || (value == (const char *) NULL)) + return(MagickFalse); + switch(domain) + { + case CachePolicyDomain: + { + if (LocaleCompare(name,"synchronize") == 0) + return(SetPolicyValue(domain,name,value)); + if (LocaleCompare(name,"memory-map") == 0) + { + if (LocaleCompare(value,"anonymous") != 0) + return(MagickFalse); + ResetCacheAnonymousMemory(); + ResetStreamAnonymousMemory(); + return(SetPolicyValue(domain,name,value)); + } + } + case SystemPolicyDomain: + { + if (LocaleCompare(name,"precision") == 0) + { + ResetMagickPrecision(); + return(SetPolicyValue(domain,name,value)); + } + if (LocaleCompare(name,"shred") == 0) + { + current_value=GetPolicyValue("system:shred"); + if ((current_value == (char *) NULL) || + (StringToInteger(value) > StringToInteger(current_value))) + return(SetPolicyValue(domain,name,value)); + } + else if (LocaleCompare(name,"memory-map") == 0) + { + if (LocaleCompare(value,"anonymous") != 0) + return(MagickFalse); + ResetVirtualAnonymousMemory(); + return(SetPolicyValue(domain,name,value)); + } + else if (LocaleCompare(name,"max-memory-request") == 0) + { + current_value=GetPolicyValue("system:max-memory-request"); + if ((current_value == (char *) NULL) || + (StringToSizeType(value,100.0) < StringToSizeType( + current_value,100.0))) + { + ResetMaxMemoryRequest(); + return(SetPolicyValue(domain,name,value)); + } + } + } + case ResourcePolicyDomain: + { + if (LocaleCompare(name,"temporary-path") == 0) + return(SetPolicyValue(domain,name,value)); + else + { + MagickSizeType + limit; + + ResourceType + type; + + type=(ResourceType) ParseCommandOption(MagickResourceOptions, + MagickFalse,value); + limit=MagickResourceInfinity; + if (LocaleCompare("unlimited",value) != 0) + limit=StringToMagickSizeType(value,100.0); + return(SetMagickResourceLimit(type,limit)); + } + } + default: + case CoderPolicyDomain: + case DelegatePolicyDomain: + case FilterPolicyDomain: + case PathPolicyDomain: + break; + } + return(MagickFalse); +} diff --git a/MagickCore/policy.h b/MagickCore/policy.h index 418d1aa06..c29af372b 100644 --- a/MagickCore/policy.h +++ b/MagickCore/policy.h @@ -60,7 +60,9 @@ extern MagickExport const PolicyInfo extern MagickExport MagickBooleanType IsRightsAuthorized(const PolicyDomain,const PolicyRights,const char *), ListPolicyInfo(FILE *,ExceptionInfo *), - SetMagickSecurityPolicy(const char *,ExceptionInfo *); + SetMagickSecurityPolicy(const char *,ExceptionInfo *), + SetMagickSecurityPolicyValue(const PolicyDomain,const char *,const char *, + ExceptionInfo *); #if defined(__cplusplus) || defined(c_plusplus) } diff --git a/MagickCore/resource.c b/MagickCore/resource.c index 078b44263..650e967e0 100644 --- a/MagickCore/resource.c +++ b/MagickCore/resource.c @@ -1172,18 +1172,6 @@ MagickExport MagickBooleanType RelinquishUniqueFileResource(const char *path) % */ -static inline MagickSizeType StringToSizeType(const char *string, - const double interval) -{ - double - value; - - value=SiPrefixToDoubleInterval(string,interval); - if (value >= (double) MagickULLConstant(~0)) - return(MagickULLConstant(~0)); - return((MagickSizeType) value); -} - MagickPrivate MagickBooleanType ResourceComponentGenesis(void) { char @@ -1206,7 +1194,7 @@ MagickPrivate MagickBooleanType ResourceComponentGenesis(void) limit=GetEnvironmentValue("MAGICK_WIDTH_LIMIT"); if (limit != (char *) NULL) { - (void) SetMagickResourceLimit(WidthResource,StringToSizeType(limit, + (void) SetMagickResourceLimit(WidthResource,StringToMagickSizeType(limit, 100.0)); limit=DestroyString(limit); } @@ -1214,8 +1202,8 @@ MagickPrivate MagickBooleanType ResourceComponentGenesis(void) limit=GetEnvironmentValue("MAGICK_HEIGHT_LIMIT"); if (limit != (char *) NULL) { - (void) SetMagickResourceLimit(HeightResource,StringToSizeType(limit, - 100.0)); + (void) SetMagickResourceLimit(HeightResource,StringToMagickSizeType( + limit,100.0)); limit=DestroyString(limit); } pagesize=GetMagickPageSize(); @@ -1233,29 +1221,32 @@ MagickPrivate MagickBooleanType ResourceComponentGenesis(void) limit=GetEnvironmentValue("MAGICK_AREA_LIMIT"); if (limit != (char *) NULL) { - (void) SetMagickResourceLimit(AreaResource,StringToSizeType(limit,100.0)); + (void) SetMagickResourceLimit(AreaResource,StringToMagickSizeType(limit, + 100.0)); limit=DestroyString(limit); } (void) SetMagickResourceLimit(MemoryResource,memory); limit=GetEnvironmentValue("MAGICK_MEMORY_LIMIT"); if (limit != (char *) NULL) { - (void) SetMagickResourceLimit(MemoryResource, - StringToSizeType(limit,100.0)); + (void) SetMagickResourceLimit(MemoryResource,StringToMagickSizeType( + limit,100.0)); limit=DestroyString(limit); } (void) SetMagickResourceLimit(MapResource,2*memory); limit=GetEnvironmentValue("MAGICK_MAP_LIMIT"); if (limit != (char *) NULL) { - (void) SetMagickResourceLimit(MapResource,StringToSizeType(limit,100.0)); + (void) SetMagickResourceLimit(MapResource,StringToMagickSizeType(limit, + 100.0)); limit=DestroyString(limit); } (void) SetMagickResourceLimit(DiskResource,MagickResourceInfinity); limit=GetEnvironmentValue("MAGICK_DISK_LIMIT"); if (limit != (char *) NULL) { - (void) SetMagickResourceLimit(DiskResource,StringToSizeType(limit,100.0)); + (void) SetMagickResourceLimit(DiskResource,StringToMagickSizeType(limit, + 100.0)); limit=DestroyString(limit); } files=(-1); @@ -1283,7 +1274,7 @@ MagickPrivate MagickBooleanType ResourceComponentGenesis(void) limit=GetEnvironmentValue("MAGICK_FILE_LIMIT"); if (limit != (char *) NULL) { - (void) SetMagickResourceLimit(FileResource,StringToSizeType(limit, + (void) SetMagickResourceLimit(FileResource,StringToMagickSizeType(limit, 100.0)); limit=DestroyString(limit); } @@ -1291,23 +1282,24 @@ MagickPrivate MagickBooleanType ResourceComponentGenesis(void) limit=GetEnvironmentValue("MAGICK_THREAD_LIMIT"); if (limit != (char *) NULL) { - (void) SetMagickResourceLimit(ThreadResource,StringToSizeType(limit, - 100.0)); + (void) SetMagickResourceLimit(ThreadResource,StringToMagickSizeType( + limit,100.0)); limit=DestroyString(limit); } (void) SetMagickResourceLimit(ThrottleResource,0); limit=GetEnvironmentValue("MAGICK_THROTTLE_LIMIT"); if (limit != (char *) NULL) { - (void) SetMagickResourceLimit(ThrottleResource,StringToSizeType(limit, - 100.0)); + (void) SetMagickResourceLimit(ThrottleResource,StringToMagickSizeType( + limit,100.0)); limit=DestroyString(limit); } (void) SetMagickResourceLimit(TimeResource,MagickResourceInfinity); limit=GetEnvironmentValue("MAGICK_TIME_LIMIT"); if (limit != (char *) NULL) { - (void) SetMagickResourceLimit(TimeResource,StringToSizeType(limit,100.0)); + (void) SetMagickResourceLimit(TimeResource,StringToMagickSizeType(limit, + 100.0)); limit=DestroyString(limit); } return(MagickTrue); @@ -1391,7 +1383,7 @@ MagickExport MagickBooleanType SetMagickResourceLimit(const ResourceType type, resource_info.width_limit=limit; value=GetPolicyValue("resource:width"); if (value != (char *) NULL) - resource_info.width_limit=MagickMin(limit,StringToSizeType(value, + resource_info.width_limit=MagickMin(limit,StringToMagickSizeType(value, 100.0)); break; } @@ -1400,8 +1392,8 @@ MagickExport MagickBooleanType SetMagickResourceLimit(const ResourceType type, resource_info.height_limit=limit; value=GetPolicyValue("resource:height"); if (value != (char *) NULL) - resource_info.height_limit=MagickMin(limit,StringToSizeType(value, - 100.0)); + resource_info.height_limit=MagickMin(limit,StringToMagickSizeType( + value,100.0)); break; } case AreaResource: @@ -1409,7 +1401,8 @@ MagickExport MagickBooleanType SetMagickResourceLimit(const ResourceType type, resource_info.area_limit=limit; value=GetPolicyValue("resource:area"); if (value != (char *) NULL) - resource_info.area_limit=MagickMin(limit,StringToSizeType(value,100.0)); + resource_info.area_limit=MagickMin(limit,StringToMagickSizeType(value, + 100.0)); break; } case MemoryResource: @@ -1417,8 +1410,8 @@ MagickExport MagickBooleanType SetMagickResourceLimit(const ResourceType type, resource_info.memory_limit=limit; value=GetPolicyValue("resource:memory"); if (value != (char *) NULL) - resource_info.memory_limit=MagickMin(limit,StringToSizeType(value, - 100.0)); + resource_info.memory_limit=MagickMin(limit,StringToMagickSizeType( + value,100.0)); break; } case MapResource: @@ -1426,7 +1419,8 @@ MagickExport MagickBooleanType SetMagickResourceLimit(const ResourceType type, resource_info.map_limit=limit; value=GetPolicyValue("resource:map"); if (value != (char *) NULL) - resource_info.map_limit=MagickMin(limit,StringToSizeType(value,100.0)); + resource_info.map_limit=MagickMin(limit,StringToMagickSizeType(value, + 100.0)); break; } case DiskResource: @@ -1434,7 +1428,8 @@ MagickExport MagickBooleanType SetMagickResourceLimit(const ResourceType type, resource_info.disk_limit=limit; value=GetPolicyValue("resource:disk"); if (value != (char *) NULL) - resource_info.disk_limit=MagickMin(limit,StringToSizeType(value,100.0)); + resource_info.disk_limit=MagickMin(limit,StringToMagickSizeType(value, + 100.0)); break; } case FileResource: @@ -1442,7 +1437,8 @@ MagickExport MagickBooleanType SetMagickResourceLimit(const ResourceType type, resource_info.file_limit=limit; value=GetPolicyValue("resource:file"); if (value != (char *) NULL) - resource_info.file_limit=MagickMin(limit,StringToSizeType(value,100.0)); + resource_info.file_limit=MagickMin(limit,StringToMagickSizeType(value, + 100.0)); break; } case ThreadResource: @@ -1450,8 +1446,8 @@ MagickExport MagickBooleanType SetMagickResourceLimit(const ResourceType type, resource_info.thread_limit=limit; value=GetPolicyValue("resource:thread"); if (value != (char *) NULL) - resource_info.thread_limit=MagickMin(limit,StringToSizeType(value, - 100.0)); + resource_info.thread_limit=MagickMin(limit,StringToMagickSizeType( + value,100.0)); if (resource_info.thread_limit > GetOpenMPMaximumThreads()) resource_info.thread_limit=GetOpenMPMaximumThreads(); else @@ -1464,8 +1460,8 @@ MagickExport MagickBooleanType SetMagickResourceLimit(const ResourceType type, resource_info.throttle_limit=limit; value=GetPolicyValue("resource:throttle"); if (value != (char *) NULL) - resource_info.throttle_limit=MagickMax(limit,StringToSizeType(value, - 100.0)); + resource_info.throttle_limit=MagickMax(limit,StringToMagickSizeType( + value,100.0)); break; } case TimeResource: @@ -1473,7 +1469,8 @@ MagickExport MagickBooleanType SetMagickResourceLimit(const ResourceType type, resource_info.time_limit=limit; value=GetPolicyValue("resource:time"); if (value != (char *) NULL) - resource_info.time_limit=MagickMin(limit,StringToSizeType(value,100.0)); + resource_info.time_limit=MagickMin(limit,StringToMagickSizeType(value, + 100.0)); ResetPixelCacheEpoch(); break; } diff --git a/MagickCore/stream-private.h b/MagickCore/stream-private.h index 41b9ed875..6a7221008 100644 --- a/MagickCore/stream-private.h +++ b/MagickCore/stream-private.h @@ -26,6 +26,7 @@ extern MagickPrivate const void *GetStreamInfoClientData(StreamInfo *); extern MagickPrivate void + ResetStreamAnonymousMemory(void), SetStreamInfoClientData(StreamInfo *,const void *); #if defined(__cplusplus) || defined(c_plusplus) diff --git a/MagickCore/stream.c b/MagickCore/stream.c index 0ccd9678e..c0f5553f6 100644 --- a/MagickCore/stream.c +++ b/MagickCore/stream.c @@ -1055,6 +1055,29 @@ MagickExport Image *ReadStream(const ImageInfo *image_info,StreamHandler stream, % % % % % % ++ R e s e t S t r e a m A n o n y m o u s M e m o r y % +% % +% % +% % +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% +% ResetStreamAnonymousMemory() resets the anonymous_memory value. +% +% The format of the ResetStreamAnonymousMemory method is: +% +% void ResetStreamAnonymousMemory(void) +% +*/ +MagickPrivate void ResetStreamAnonymousMemory(void) +{ + cache_anonymous_memory=0; +} + +/* +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% % +% % +% % + S e t S t r e a m I n f o C l i e n t D a t a % % % % % diff --git a/MagickCore/string-private.h b/MagickCore/string-private.h index b077f7ed2..7127a39e6 100644 --- a/MagickCore/string-private.h +++ b/MagickCore/string-private.h @@ -70,6 +70,30 @@ static inline long StringToLong(const char *magick_restrict value) return(strtol(value,(char **) NULL,10)); } +static inline MagickSizeType StringToMagickSizeType(const char *string, + const double interval) +{ + double + value; + + value=SiPrefixToDoubleInterval(string,interval); + if (value >= (double) MagickULLConstant(~0)) + return(MagickULLConstant(~0)); + return((MagickSizeType) value); +} + +static inline size_t StringToSizeType(const char *string, + const double interval) +{ + double + value; + + value=SiPrefixToDoubleInterval(string,interval); + if (value >= (double) MagickULLConstant(~0)) + return((size_t) MagickULLConstant(~0)); + return((size_t) value); +} + static inline unsigned long StringToUnsignedLong( const char *magick_restrict value) { -- 2.40.0