From ac316146d720428b7a3b0ccca77d2f4fd7958f1f Mon Sep 17 00:00:00 2001 From: mrbean-bremen Date: Sat, 11 Mar 2017 20:42:45 +0100 Subject: [PATCH] Prevent crashes on zero length segments or paths - fixes __tiger.svg test image --- Source/Paths/SvgClosePathSegment.cs | 7 ++++++- Source/Paths/SvgLineSegment.cs | 5 ++++- Source/Paths/SvgMoveToSegment.cs | 5 ++++- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/Source/Paths/SvgClosePathSegment.cs b/Source/Paths/SvgClosePathSegment.cs index d0c7ffb..8ad928a 100644 --- a/Source/Paths/SvgClosePathSegment.cs +++ b/Source/Paths/SvgClosePathSegment.cs @@ -8,10 +8,15 @@ namespace Svg.Pathing { public override void AddToPath(System.Drawing.Drawing2D.GraphicsPath graphicsPath) { + if (graphicsPath.PointCount == 0) + { + return; + } + // Important for custom line caps. Force the path the close with an explicit line, not just an implicit close of the figure. var pathPoints = graphicsPath.PathPoints; - if (pathPoints.Length > 0 && !pathPoints[0].Equals(pathPoints[pathPoints.Length - 1])) + if (!pathPoints[0].Equals(pathPoints[pathPoints.Length - 1])) { var pathTypes = graphicsPath.PathTypes; int i = pathPoints.Length - 1; diff --git a/Source/Paths/SvgLineSegment.cs b/Source/Paths/SvgLineSegment.cs index 61ed708..1492dd3 100644 --- a/Source/Paths/SvgLineSegment.cs +++ b/Source/Paths/SvgLineSegment.cs @@ -15,7 +15,10 @@ namespace Svg.Pathing public override void AddToPath(System.Drawing.Drawing2D.GraphicsPath graphicsPath) { - graphicsPath.AddLine(this.Start, this.End); + if (this.Start != this.End) + { + graphicsPath.AddLine(this.Start, this.End); + } } public override string ToString() diff --git a/Source/Paths/SvgMoveToSegment.cs b/Source/Paths/SvgMoveToSegment.cs index e9e1e3c..1b49315 100644 --- a/Source/Paths/SvgMoveToSegment.cs +++ b/Source/Paths/SvgMoveToSegment.cs @@ -15,7 +15,10 @@ namespace Svg.Pathing public override void AddToPath(System.Drawing.Drawing2D.GraphicsPath graphicsPath) { - graphicsPath.StartFigure(); + if (this.Start != this.End) + { + graphicsPath.StartFigure(); + } } public override string ToString() -- GitLab