From 2cc321b9185251011239abefb3dcbf8485b5ec48 Mon Sep 17 00:00:00 2001 From: Kenny Burns Date: Tue, 1 Jul 2014 15:46:35 +0100 Subject: [PATCH 1/2] Minor update to DiskCache to prevent unauthorized permission issue over UNC share Former-commit-id: 008c93864acf43615d07e608a5193a696449ac2f --- .../NET45/Caching/DiskCache.cs | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/ImageProcessor.Web/NET45/Caching/DiskCache.cs b/src/ImageProcessor.Web/NET45/Caching/DiskCache.cs index 7d4150f45..421070612 100644 --- a/src/ImageProcessor.Web/NET45/Caching/DiskCache.cs +++ b/src/ImageProcessor.Web/NET45/Caching/DiskCache.cs @@ -51,7 +51,7 @@ namespace ImageProcessor.Web.Caching /// /// The absolute path to virtual cache path on the server. /// - private static readonly string AbsoluteCachePath = HostingEnvironment.MapPath(ImageProcessorConfig.Instance.VirtualCachePath); + public static readonly string AbsoluteCachePath = HostingEnvironment.MapPath(ImageProcessorConfig.Instance.VirtualCachePath); /// /// The request for the image. @@ -229,7 +229,7 @@ namespace ImageProcessor.Web.Caching DirectoryInfo parentDirectoryInfo = directoryInfo.Parent; // ReSharper disable once PossibleNullReferenceException - foreach (DirectoryInfo enumerateDirectory in parentDirectoryInfo.EnumerateDirectories()) + foreach (DirectoryInfo enumerateDirectory in SafeEnumerateDirectories(parentDirectoryInfo)) { IEnumerable files = enumerateDirectory.EnumerateFiles().OrderBy(f => f.CreationTimeUtc); int count = files.Count(); @@ -260,6 +260,22 @@ namespace ImageProcessor.Web.Caching } } + public static IEnumerable SafeEnumerateDirectories(DirectoryInfo directoryInfo) + { + IEnumerable directories; + + try + { + directories = directoryInfo.EnumerateDirectories(); + } + catch + { + return Enumerable.Empty(); + } + + return directories; + } + /// /// Gets the full transformed cached path for the image. /// The images are stored in paths that are based upon the sha1 of their full request path From ace4c0d69e27cd534a9148d610ebecddbe779dcd Mon Sep 17 00:00:00 2001 From: Kenny Burns Date: Tue, 1 Jul 2014 15:51:43 +0100 Subject: [PATCH 2/2] Revert AbsoluteCachePath back to original (private) Former-commit-id: 558d3c9b5266e63f50efbd43b851996e0a834b0b --- src/ImageProcessor.Web/NET45/Caching/DiskCache.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ImageProcessor.Web/NET45/Caching/DiskCache.cs b/src/ImageProcessor.Web/NET45/Caching/DiskCache.cs index 421070612..1cdcfcb2f 100644 --- a/src/ImageProcessor.Web/NET45/Caching/DiskCache.cs +++ b/src/ImageProcessor.Web/NET45/Caching/DiskCache.cs @@ -51,7 +51,7 @@ namespace ImageProcessor.Web.Caching /// /// The absolute path to virtual cache path on the server. /// - public static readonly string AbsoluteCachePath = HostingEnvironment.MapPath(ImageProcessorConfig.Instance.VirtualCachePath); + private static readonly string AbsoluteCachePath = HostingEnvironment.MapPath(ImageProcessorConfig.Instance.VirtualCachePath); /// /// The request for the image.