From 1d2d717a50909135ef44e0427dbb30f81fc8424c Mon Sep 17 00:00:00 2001 From: Ynse Hoornenborg Date: Fri, 11 Mar 2022 12:24:01 +0100 Subject: [PATCH] Fix and test --- .../Metadata/Profiles/Exif/Values/ExifValue.cs | 2 +- .../Formats/Jpg/JpegDecoderTests.Metadata.cs | 13 +++++++++++++ tests/ImageSharp.Tests/TestImages.cs | 1 + .../Input/Jpg/issues/issue-2056-exif-null-array.jpg | 3 +++ 4 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 tests/Images/Input/Jpg/issues/issue-2056-exif-null-array.jpg diff --git a/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifValue.cs b/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifValue.cs index 314333919..82bd6ad2e 100644 --- a/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifValue.cs +++ b/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifValue.cs @@ -29,7 +29,7 @@ namespace SixLabors.ImageSharp.Metadata.Profiles.Exif { // All array types are value types so Clone() is sufficient here. var array = (Array)other.GetValue(); - this.TrySetValue(array.Clone()); + this.TrySetValue(array?.Clone()); } } diff --git a/tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.Metadata.cs b/tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.Metadata.cs index 840cc9f68..cd55c98ea 100644 --- a/tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.Metadata.cs +++ b/tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.Metadata.cs @@ -302,6 +302,19 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg Assert.Null(ex); } + [Theory] + [WithFile(TestImages.Jpeg.Issues.ExifNullArrayTag, PixelTypes.Rgba32)] + public void Clone_WithNullRationalArrayTag_DoesNotThrowException(TestImageProvider provider) + where TPixel : unmanaged, IPixel + { + Exception ex = Record.Exception(() => + { + using Image image = provider.GetImage(JpegDecoder); + var clone = image.Metadata.ExifProfile.DeepClone(); + }); + Assert.Null(ex); + } + [Fact] public void EncodedStringTags_WriteAndRead() { diff --git a/tests/ImageSharp.Tests/TestImages.cs b/tests/ImageSharp.Tests/TestImages.cs index aa4314b8e..39fede914 100644 --- a/tests/ImageSharp.Tests/TestImages.cs +++ b/tests/ImageSharp.Tests/TestImages.cs @@ -262,6 +262,7 @@ namespace SixLabors.ImageSharp.Tests public const string MalformedUnsupportedComponentCount = "Jpg/issues/issue-1900-malformed-unsupported-255-components.jpg"; public const string MultipleApp01932 = "Jpg/issues/issue-1932-app0-resolution.jpg"; public const string InvalidIptcTag = "Jpg/issues/Issue1942InvalidIptcTag.jpg"; + public const string ExifNullArrayTag = "Jpg/issues/issue-2056-exif-null-array.jpg"; public static class Fuzz { diff --git a/tests/Images/Input/Jpg/issues/issue-2056-exif-null-array.jpg b/tests/Images/Input/Jpg/issues/issue-2056-exif-null-array.jpg new file mode 100644 index 000000000..9b5bc8303 --- /dev/null +++ b/tests/Images/Input/Jpg/issues/issue-2056-exif-null-array.jpg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:4c52500be37a8ea1ee1caeb78c79e44b02e10912df4f6db65313c6745573c8ee +size 250451