From d54eabcda8031a2633de6d21372575ab3e09183b Mon Sep 17 00:00:00 2001 From: Dirk Lemstra Date: Sat, 19 May 2018 22:45:42 +0200 Subject: [PATCH 1/2] Fixed bug when marking a value as an array. --- src/ImageSharp/MetaData/Profiles/Exif/ExifReader.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ImageSharp/MetaData/Profiles/Exif/ExifReader.cs b/src/ImageSharp/MetaData/Profiles/Exif/ExifReader.cs index c00eec601..4f28449d6 100644 --- a/src/ImageSharp/MetaData/Profiles/Exif/ExifReader.cs +++ b/src/ImageSharp/MetaData/Profiles/Exif/ExifReader.cs @@ -387,7 +387,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Exif value = this.ConvertValue(dataType, offsetBuffer, numberOfComponents); } - exifValue = new ExifValue(tag, dataType, value, isArray: value != null && numberOfComponents > 1); + exifValue = new ExifValue(tag, dataType, value, isArray: value != null && numberOfComponents != 1); return true; } From e62786a6a0bc32d4eab54ffac23a639002658bfd Mon Sep 17 00:00:00 2001 From: Dirk Lemstra Date: Mon, 21 May 2018 11:50:04 +0200 Subject: [PATCH 2/2] Added unit test. --- .../MetaData/Profiles/Exif/ExifProfileTests.cs | 16 ++++++++++++++++ tests/ImageSharp.Tests/TestImages.cs | 1 + .../Input/Jpg/issues/Issue520-InvalidCast.jpg | 3 +++ 3 files changed, 20 insertions(+) create mode 100644 tests/Images/Input/Jpg/issues/Issue520-InvalidCast.jpg diff --git a/tests/ImageSharp.Tests/MetaData/Profiles/Exif/ExifProfileTests.cs b/tests/ImageSharp.Tests/MetaData/Profiles/Exif/ExifProfileTests.cs index d98c61279..3c69b57fd 100644 --- a/tests/ImageSharp.Tests/MetaData/Profiles/Exif/ExifProfileTests.cs +++ b/tests/ImageSharp.Tests/MetaData/Profiles/Exif/ExifProfileTests.cs @@ -292,6 +292,22 @@ namespace SixLabors.ImageSharp.Tests } } + [Fact] + public void TestArrayValueWithUnspecifiedSize() + { + // This images contains array in the exif profile that has zero components. + Image image = TestFile.Create(TestImages.Jpeg.Issues.InvalidCast520).CreateImage(); + + ExifProfile profile = image.MetaData.ExifProfile; + Assert.NotNull(profile); + + // Force parsing of the profile. + Assert.Equal(24, profile.Values.Count); + + byte[] bytes = profile.ToByteArray(); + Assert.Equal(495, bytes.Length); + } + private static ExifProfile GetExifProfile() { Image image = TestFile.Create(TestImages.Jpeg.Baseline.Floorplan).CreateImage(); diff --git a/tests/ImageSharp.Tests/TestImages.cs b/tests/ImageSharp.Tests/TestImages.cs index 85f12bc80..d261f9497 100644 --- a/tests/ImageSharp.Tests/TestImages.cs +++ b/tests/ImageSharp.Tests/TestImages.cs @@ -136,6 +136,7 @@ namespace SixLabors.ImageSharp.Tests public const string MultiHuffmanBaseline394 = "Jpg/issues/Issue394-MultiHuffmanBaseline-Speakers.jpg"; public const string NoEoiProgressive517 = "Jpg/issues/Issue517-No-EOI-Progressive.jpg"; public const string BadRstProgressive518 = "Jpg/issues/Issue518-Bad-RST-Progressive.jpg"; + public const string InvalidCast520 = "Jpg/issues/Issue520-InvalidCast.jpg"; } public static readonly string[] All = Baseline.All.Concat(Progressive.All).ToArray(); diff --git a/tests/Images/Input/Jpg/issues/Issue520-InvalidCast.jpg b/tests/Images/Input/Jpg/issues/Issue520-InvalidCast.jpg new file mode 100644 index 000000000..9f0adf458 --- /dev/null +++ b/tests/Images/Input/Jpg/issues/Issue520-InvalidCast.jpg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:3fe23e56bf22a220efdc75cb98e7c9a7a5e29ca960be5e5dc5ca3a0a33d8cd2c +size 7751