Skip to content

Commit e73f21f

Browse files
authored
Merge pull request #2059 from ynse01/issue-exif-null-array-value
Fix null reference exception on Exif clone of null ExifArrayValue
2 parents 823e785 + cfa1510 commit e73f21f

File tree

4 files changed

+18
-1
lines changed

4 files changed

+18
-1
lines changed

src/ImageSharp/Metadata/Profiles/Exif/Values/ExifValue.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ internal ExifValue(ExifValue other)
2929
{
3030
// All array types are value types so Clone() is sufficient here.
3131
var array = (Array)other.GetValue();
32-
this.TrySetValue(array.Clone());
32+
this.TrySetValue(array?.Clone());
3333
}
3434
}
3535

tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.Metadata.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,19 @@ public void Decode_WithInvalidIptcTag_DoesNotThrowException<TPixel>(TestImagePro
302302
Assert.Null(ex);
303303
}
304304

305+
[Theory]
306+
[WithFile(TestImages.Jpeg.Issues.ExifNullArrayTag, PixelTypes.Rgba32)]
307+
public void Clone_WithNullRationalArrayTag_DoesNotThrowException<TPixel>(TestImageProvider<TPixel> provider)
308+
where TPixel : unmanaged, IPixel<TPixel>
309+
{
310+
Exception ex = Record.Exception(() =>
311+
{
312+
using Image<TPixel> image = provider.GetImage(JpegDecoder);
313+
var clone = image.Metadata.ExifProfile.DeepClone();
314+
});
315+
Assert.Null(ex);
316+
}
317+
305318
[Fact]
306319
public void EncodedStringTags_WriteAndRead()
307320
{

tests/ImageSharp.Tests/TestImages.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,7 @@ public static class Issues
262262
public const string MalformedUnsupportedComponentCount = "Jpg/issues/issue-1900-malformed-unsupported-255-components.jpg";
263263
public const string MultipleApp01932 = "Jpg/issues/issue-1932-app0-resolution.jpg";
264264
public const string InvalidIptcTag = "Jpg/issues/Issue1942InvalidIptcTag.jpg";
265+
public const string ExifNullArrayTag = "Jpg/issues/issue-2056-exif-null-array.jpg";
265266

266267
public static class Fuzz
267268
{
Lines changed: 3 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)