From 6f25887d5bbfce869b9a47c731ce1bac7d7d1249 Mon Sep 17 00:00:00 2001 From: Frederik Carlier Date: Fri, 22 Sep 2017 08:46:12 +0200 Subject: [PATCH] Throw an exception when the filename length > MAX_PATH Commit migrated from https://github.com/dotnet/corefx/commit/926c12917fac0e7d6ec2ed1ff25dd5f03ad0665a --- .../src/System/Drawing/Imaging/Metafile.Windows.cs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/libraries/System.Drawing.Common/src/System/Drawing/Imaging/Metafile.Windows.cs b/src/libraries/System.Drawing.Common/src/System/Drawing/Imaging/Metafile.Windows.cs index 286ef7e..7a3c6b2 100644 --- a/src/libraries/System.Drawing.Common/src/System/Drawing/Imaging/Metafile.Windows.cs +++ b/src/libraries/System.Drawing.Common/src/System/Drawing/Imaging/Metafile.Windows.cs @@ -14,6 +14,9 @@ namespace System.Drawing.Imaging /// public sealed partial class Metafile : Image { + // GDI+ doesn't handle filenames over MAX_PATH very well + private const int MaxPath = 260; + /// /// Initializes a new instance of the class from the specified handle and /// . @@ -300,6 +303,11 @@ namespace System.Drawing.Imaging // Called in order to emulate exception behavior from netfx related to invalid file paths. Path.GetFullPath(fileName); + if (fileName.Length > MaxPath) + { + throw new PathTooLongException(); + } + IntPtr metafile = IntPtr.Zero; GPRECTF rectf = new GPRECTF(frameRect); -- 2.7.4