From: Cristy Date: Thu, 16 Feb 2017 13:27:38 +0000 (-0500) Subject: Support pixel-cache and shred security policies X-Git-Tag: 7.0.4-10~10 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=e81038040ca2f04372e9eb779d366b983a39b015;p=imagemagick Support pixel-cache and shred security policies --- diff --git a/ChangeLog b/ChangeLog index 5e33e4a83..e42dddcf1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -2,6 +2,7 @@ * Prevent random pixel data for corrupt JPEG image (bug report from Hirokazu Moriguchi, Sony). * Restore -mattecolor option. + * Support pixel-cache and shred security policies. 2017-02-14 7.0.4-9 Cristy * Release ImageMagick version 7.0.4-9, GIT revision 19580:d474b37:20170214. diff --git a/MagickCore/cache.c b/MagickCore/cache.c index a22adb483..c7f112449 100644 --- a/MagickCore/cache.c +++ b/MagickCore/cache.c @@ -3478,14 +3478,40 @@ static MagickBooleanType OpenPixelCache(Image *image,const MapMode mode, cache_info->metacontent_extent); if ((status != MagickFalse) && (length == (MagickSizeType) ((size_t) length))) { + static ssize_t + anonymous_pixel_cache = (-1); + + if (anonymous_pixel_cache < 0) + { + char + *value; + + /* + Does the security policy require anonymous mapping for pixel cache? + */ + anonymous_pixel_cache=0; + value=GetPolicyValue("pixel-cache"); + if (LocaleCompare(value,"anonymous") == 0) + anonymous_pixel_cache=1; + value=DestroyString(value); + } status=AcquireMagickResource(MemoryResource,cache_info->length); if (((cache_info->type == UndefinedCache) && (status != MagickFalse)) || (cache_info->type == MemoryCache)) { status=MagickTrue; - cache_info->mapped=MagickFalse; - cache_info->pixels=(Quantum *) MagickAssumeAligned( - AcquireAlignedMemory(1,(size_t) cache_info->length)); + if (anonymous_pixel_cache == 0) + { + cache_info->mapped=MagickFalse; + cache_info->pixels=(Quantum *) MagickAssumeAligned( + AcquireAlignedMemory(1,(size_t) cache_info->length)); + } + else + { + cache_info->mapped=MagickTrue; + cache_info->pixels=(Quantum *) MapBlob(-1,IOMode,0,(size_t) + cache_info->length); + } if (cache_info->pixels == (Quantum *) NULL) cache_info->pixels=source_info.pixels; else diff --git a/MagickCore/utility.c b/MagickCore/utility.c index 2e48a7530..ebe8d5d67 100644 --- a/MagickCore/utility.c +++ b/MagickCore/utility.c @@ -1826,7 +1826,9 @@ MagickPrivate MagickBooleanType ShredFile(const char *path) if ((path == (const char *) NULL) || (*path == '\0')) return(MagickFalse); - passes=GetEnvironmentValue("MAGICK_SHRED_PASSES"); + passes=GetPolicyValue("shred"); + if (passes == (char *) NULL) + passes=GetEnvironmentValue("MAGICK_SHRED_PASSES"); if (passes == (char *) NULL) { /* diff --git a/config/policy.xml b/config/policy.xml index a09c4a959..64fcae940 100644 --- a/config/policy.xml +++ b/config/policy.xml @@ -68,6 +68,8 @@ + +