From a18af5d33f61c8f6d274a15a31e86f773d9af761 Mon Sep 17 00:00:00 2001 From: Shalini-Ashokan <102292178+Shalini-Ashokan@users.noreply.github.com> Date: Mon, 15 Dec 2025 16:43:41 +0530 Subject: [PATCH 1/4] Fix the Svg file Null reference exception issue --- src/SingleProject/Resizetizer/src/SkiaSharpSvgTools.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/SingleProject/Resizetizer/src/SkiaSharpSvgTools.cs b/src/SingleProject/Resizetizer/src/SkiaSharpSvgTools.cs index ea2bed844b0b0..86e02af0c2281 100644 --- a/src/SingleProject/Resizetizer/src/SkiaSharpSvgTools.cs +++ b/src/SingleProject/Resizetizer/src/SkiaSharpSvgTools.cs @@ -44,6 +44,10 @@ public override void DrawUnscaled(SKCanvas canvas, float scale) { // draw using raster downscaling var size = GetOriginalSize(); + if (size.IsEmpty) + { + throw new InvalidOperationException($"Cannot draw SVG file '{Filename}'. The SVG has an no size and may be missing width/height or viewBox attributes."); + } // vector scaling has rounding issues, so first draw as intended var info = new SKImageInfo((int)size.Width, (int)size.Height); From 98f8759812617915498284531192aecbcb25b5e8 Mon Sep 17 00:00:00 2001 From: Shalini-Ashokan <102292178+Shalini-Ashokan@users.noreply.github.com> Date: Tue, 16 Dec 2025 17:26:15 +0530 Subject: [PATCH 2/4] Added a unit test. --- .../test/UnitTests/SkiaSharpSvgToolsTests.cs | 25 +++++++++++++++++++ .../test/UnitTests/images/no_viewbox.svg | 4 +++ 2 files changed, 29 insertions(+) create mode 100644 src/SingleProject/Resizetizer/test/UnitTests/images/no_viewbox.svg diff --git a/src/SingleProject/Resizetizer/test/UnitTests/SkiaSharpSvgToolsTests.cs b/src/SingleProject/Resizetizer/test/UnitTests/SkiaSharpSvgToolsTests.cs index b549619e894ea..555df10d0d5a1 100644 --- a/src/SingleProject/Resizetizer/test/UnitTests/SkiaSharpSvgToolsTests.cs +++ b/src/SingleProject/Resizetizer/test/UnitTests/SkiaSharpSvgToolsTests.cs @@ -332,6 +332,31 @@ public void SvgImageWithDecodingIssue_12109() Assert.Equal((SKColor)0xffe26b00, pixmap.GetPixelColor(20, 3)); Assert.Equal((SKColor)0xffe26b00, pixmap.GetPixelColor(20, 34)); } + + [Fact] + public void SvgWithoutViewBoxThrowsInvalidOperationException_32460() + { + var info = new ResizeImageInfo(); + info.Filename = "images/no_viewbox.svg"; + var tools = new SkiaSharpSvgTools(info, Logger); + var dpiPath = new DpiPath("", 0.5m); + + // On Mac/Windows: SkiaSharp infers size from width/height, no exception + // On Android/iOS: SkiaSharp requires viewBox, throws exception + var size = tools.GetOriginalSize(); + if (size.IsEmpty) + { + var exception = Assert.Throws(() => tools.Resize(dpiPath, DestinationFilename)); + Assert.Contains("may be missing width/height or viewBox attributes", exception.Message, StringComparison.Ordinal); + } + else + { + tools.Resize(dpiPath, DestinationFilename); + using var resultImage = SKBitmap.Decode(DestinationFilename); + Assert.True(resultImage.Width > 0); + Assert.True(resultImage.Height > 0); + } + } } } } diff --git a/src/SingleProject/Resizetizer/test/UnitTests/images/no_viewbox.svg b/src/SingleProject/Resizetizer/test/UnitTests/images/no_viewbox.svg new file mode 100644 index 0000000000000..2c6f60b315128 --- /dev/null +++ b/src/SingleProject/Resizetizer/test/UnitTests/images/no_viewbox.svg @@ -0,0 +1,4 @@ + + + + From 58f9f0b09c4cfc73644bb2782e029845a598f6c5 Mon Sep 17 00:00:00 2001 From: Shalini-Ashokan <102292178+Shalini-Ashokan@users.noreply.github.com> Date: Wed, 17 Dec 2025 12:36:19 +0530 Subject: [PATCH 3/4] Removed the test case --- .../Resizetizer/src/SkiaSharpSvgTools.cs | 2 +- .../test/UnitTests/SkiaSharpSvgToolsTests.cs | 25 ------------------- .../test/UnitTests/images/no_viewbox.svg | 4 --- 3 files changed, 1 insertion(+), 30 deletions(-) delete mode 100644 src/SingleProject/Resizetizer/test/UnitTests/images/no_viewbox.svg diff --git a/src/SingleProject/Resizetizer/src/SkiaSharpSvgTools.cs b/src/SingleProject/Resizetizer/src/SkiaSharpSvgTools.cs index 86e02af0c2281..22b866a7485a4 100644 --- a/src/SingleProject/Resizetizer/src/SkiaSharpSvgTools.cs +++ b/src/SingleProject/Resizetizer/src/SkiaSharpSvgTools.cs @@ -46,7 +46,7 @@ public override void DrawUnscaled(SKCanvas canvas, float scale) var size = GetOriginalSize(); if (size.IsEmpty) { - throw new InvalidOperationException($"Cannot draw SVG file '{Filename}'. The SVG has an no size and may be missing width/height or viewBox attributes."); + throw new InvalidOperationException($"Cannot draw SVG file '{Filename}'. The SVG has no size and may be missing width/height or viewBox attributes."); } // vector scaling has rounding issues, so first draw as intended diff --git a/src/SingleProject/Resizetizer/test/UnitTests/SkiaSharpSvgToolsTests.cs b/src/SingleProject/Resizetizer/test/UnitTests/SkiaSharpSvgToolsTests.cs index 555df10d0d5a1..b549619e894ea 100644 --- a/src/SingleProject/Resizetizer/test/UnitTests/SkiaSharpSvgToolsTests.cs +++ b/src/SingleProject/Resizetizer/test/UnitTests/SkiaSharpSvgToolsTests.cs @@ -332,31 +332,6 @@ public void SvgImageWithDecodingIssue_12109() Assert.Equal((SKColor)0xffe26b00, pixmap.GetPixelColor(20, 3)); Assert.Equal((SKColor)0xffe26b00, pixmap.GetPixelColor(20, 34)); } - - [Fact] - public void SvgWithoutViewBoxThrowsInvalidOperationException_32460() - { - var info = new ResizeImageInfo(); - info.Filename = "images/no_viewbox.svg"; - var tools = new SkiaSharpSvgTools(info, Logger); - var dpiPath = new DpiPath("", 0.5m); - - // On Mac/Windows: SkiaSharp infers size from width/height, no exception - // On Android/iOS: SkiaSharp requires viewBox, throws exception - var size = tools.GetOriginalSize(); - if (size.IsEmpty) - { - var exception = Assert.Throws(() => tools.Resize(dpiPath, DestinationFilename)); - Assert.Contains("may be missing width/height or viewBox attributes", exception.Message, StringComparison.Ordinal); - } - else - { - tools.Resize(dpiPath, DestinationFilename); - using var resultImage = SKBitmap.Decode(DestinationFilename); - Assert.True(resultImage.Width > 0); - Assert.True(resultImage.Height > 0); - } - } } } } diff --git a/src/SingleProject/Resizetizer/test/UnitTests/images/no_viewbox.svg b/src/SingleProject/Resizetizer/test/UnitTests/images/no_viewbox.svg deleted file mode 100644 index 2c6f60b315128..0000000000000 --- a/src/SingleProject/Resizetizer/test/UnitTests/images/no_viewbox.svg +++ /dev/null @@ -1,4 +0,0 @@ - - - - From d5f2afdbf85f91d49aa74516b973923e62cdabdf Mon Sep 17 00:00:00 2001 From: Shalini-Ashokan <102292178+Shalini-Ashokan@users.noreply.github.com> Date: Tue, 17 Feb 2026 15:38:02 +0530 Subject: [PATCH 4/4] I modified the fix --- .../Resizetizer/src/SkiaSharpSvgTools.cs | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/SingleProject/Resizetizer/src/SkiaSharpSvgTools.cs b/src/SingleProject/Resizetizer/src/SkiaSharpSvgTools.cs index 22b866a7485a4..eb84b186321ce 100644 --- a/src/SingleProject/Resizetizer/src/SkiaSharpSvgTools.cs +++ b/src/SingleProject/Resizetizer/src/SkiaSharpSvgTools.cs @@ -35,6 +35,11 @@ public override SKSize GetOriginalSize() => public override void DrawUnscaled(SKCanvas canvas, float scale) { + var size = GetOriginalSize(); + if (size.IsEmpty) + { + throw new InvalidOperationException($"Cannot draw SVG file '{Filename}'. The SVG has no size. Ensure the SVG includes a viewBox attribute or both width and height attributes with valid dimensions."); + } if (scale >= 1) { // draw using default scaling @@ -42,13 +47,6 @@ public override void DrawUnscaled(SKCanvas canvas, float scale) } else { - // draw using raster downscaling - var size = GetOriginalSize(); - if (size.IsEmpty) - { - throw new InvalidOperationException($"Cannot draw SVG file '{Filename}'. The SVG has no size and may be missing width/height or viewBox attributes."); - } - // vector scaling has rounding issues, so first draw as intended var info = new SKImageInfo((int)size.Width, (int)size.Height); using var surface = SKSurface.Create(info);