Skip to content

Commit 90272b4

Browse files
authored
Merge pull request #582 from SixLabors/exif-fix-array
Fixed bug when marking a value as an array.
2 parents bf55d59 + 1cf4af6 commit 90272b4

File tree

4 files changed

+18
-1
lines changed

4 files changed

+18
-1
lines changed

src/ImageSharp/MetaData/Profiles/Exif/ExifReader.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ private bool TryReadValue(out ExifValue exifValue)
387387
value = this.ConvertValue(dataType, offsetBuffer, numberOfComponents);
388388
}
389389

390-
exifValue = new ExifValue(tag, dataType, value, isArray: value != null && numberOfComponents > 1);
390+
exifValue = new ExifValue(tag, dataType, value, isArray: value != null && numberOfComponents != 1);
391391

392392
return true;
393393
}

tests/ImageSharp.Tests/MetaData/Profiles/Exif/ExifProfileTests.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,22 @@ public void ExifTypeUndefined()
292292
}
293293
}
294294

295+
[Fact]
296+
public void TestArrayValueWithUnspecifiedSize()
297+
{
298+
// This images contains array in the exif profile that has zero components.
299+
Image<Rgba32> image = TestFile.Create(TestImages.Jpeg.Issues.InvalidCast520).CreateImage();
300+
301+
ExifProfile profile = image.MetaData.ExifProfile;
302+
Assert.NotNull(profile);
303+
304+
// Force parsing of the profile.
305+
Assert.Equal(24, profile.Values.Count);
306+
307+
byte[] bytes = profile.ToByteArray();
308+
Assert.Equal(495, bytes.Length);
309+
}
310+
295311
private static ExifProfile GetExifProfile()
296312
{
297313
Image<Rgba32> image = TestFile.Create(TestImages.Jpeg.Baseline.Floorplan).CreateImage();

tests/ImageSharp.Tests/TestImages.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ public class Issues
136136
public const string MultiHuffmanBaseline394 = "Jpg/issues/Issue394-MultiHuffmanBaseline-Speakers.jpg";
137137
public const string NoEoiProgressive517 = "Jpg/issues/Issue517-No-EOI-Progressive.jpg";
138138
public const string BadRstProgressive518 = "Jpg/issues/Issue518-Bad-RST-Progressive.jpg";
139+
public const string InvalidCast520 = "Jpg/issues/Issue520-InvalidCast.jpg";
139140
}
140141

141142
public static readonly string[] All = Baseline.All.Concat(Progressive.All).ToArray();
7.57 KB
Loading

0 commit comments

Comments
 (0)