Commit a0da74b0 authored by AKH's avatar AKH
Browse files

Issue 225 - Image with large embedded image fails to render

- Changed SvgImage.Href property from Uri type to String to avoid UriFormatException if Uri contains too much data
- Changed GetImage to receive a string instead of Uri object.
  - Created a temp Uri object in method with substring of allowed length and using this to determine Uri characteristics
parent 32319fd1
...@@ -74,9 +74,9 @@ namespace Svg ...@@ -74,9 +74,9 @@ namespace Svg
} }
[SvgAttribute("href", SvgAttributeAttribute.XLinkNamespace)] [SvgAttribute("href", SvgAttributeAttribute.XLinkNamespace)]
public virtual Uri Href public virtual string Href
{ {
get { return this.Attributes.GetAttribute<Uri>("href"); } get { return this.Attributes.GetAttribute<string>("href"); }
set { this.Attributes["href"] = value; } set { this.Attributes["href"] = value; }
} }
...@@ -232,14 +232,15 @@ namespace Svg ...@@ -232,14 +232,15 @@ namespace Svg
} }
} }
protected object GetImage(Uri uri) protected object GetImage(string uriString)
{ {
try try
{ {
var uri = new Uri(uriString.Substring(0, 65519)); //Uri MaxLength is 65519 (https://msdn.microsoft.com/en-us/library/z6c2z492.aspx)
// handle data/uri embedded images (http://en.wikipedia.org/wiki/Data_URI_scheme) // handle data/uri embedded images (http://en.wikipedia.org/wiki/Data_URI_scheme)
if (uri.IsAbsoluteUri && uri.Scheme == "data") if (uri.IsAbsoluteUri && uri.Scheme == "data")
{ {
string uriString = uri.OriginalString;
int dataIdx = uriString.IndexOf(",") + 1; int dataIdx = uriString.IndexOf(",") + 1;
if (dataIdx <= 0 || dataIdx + 1 > uriString.Length) if (dataIdx <= 0 || dataIdx + 1 > uriString.Length)
throw new Exception("Invalid data URI"); throw new Exception("Invalid data URI");
...@@ -284,7 +285,7 @@ namespace Svg ...@@ -284,7 +285,7 @@ namespace Svg
} }
catch (Exception ex) catch (Exception ex)
{ {
Trace.TraceError("Error loading image: '{0}', error: {1} ", uri, ex.Message); Trace.TraceError("Error loading image: '{0}', error: {1} ", uriString, ex.Message);
return null; return null;
} }
} }
......
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Svg.DataTypes;
using System;
using System.Diagnostics;
using System.Drawing;
using System.IO;
namespace Svg.UnitTests
{
/// <summary>
/// Test Class of rendering SVGs with a large embedded image
/// Based on Issue 225
/// </summary>
/// <remarks>
/// Test use the following embedded resources:
/// - Issue225_LargeUri\Speedometer.svg
/// </remarks>
[TestClass]
public class LargeEmbeddedImageTest : SvgTestHelper
{
protected override string TestResource { get { return GetFullResourceString("Issue225_LargeUri.Speedometer.svg"); } }
protected override int ExpectedSize { get { return 160000; } }
[TestMethod]
public void TestImageIsRendered()
{
LoadSvg(GetXMLDocFromResource());
}
}
}
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -55,6 +55,7 @@ ...@@ -55,6 +55,7 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="CssQueryTest.cs" /> <Compile Include="CssQueryTest.cs" />
<Compile Include="LargeEmbeddedImageTest.cs" />
<Compile Include="MarkerEndTest.cs" /> <Compile Include="MarkerEndTest.cs" />
<Compile Include="MetafileRenderingTest.cs" /> <Compile Include="MetafileRenderingTest.cs" />
<Compile Include="MultiThreadingTest.cs" /> <Compile Include="MultiThreadingTest.cs" />
...@@ -81,6 +82,9 @@ ...@@ -81,6 +82,9 @@
<ItemGroup> <ItemGroup>
<EmbeddedResource Include="Resources\Issue212_MakerEnd\OperatingPlan.svg" /> <EmbeddedResource Include="Resources\Issue212_MakerEnd\OperatingPlan.svg" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Resources\Issue225_LargeUri\Speedometer.svg" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets. Other similar extension points exist, see Microsoft.Common.targets.
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment