Browse Source

Added extra checks to the ExifReader (fixes #175).

af/merge-core
Dirk Lemstra 9 years ago
parent
commit
35b276237a
  1. 10
      src/ImageSharp/MetaData/Profiles/Exif/ExifReader.cs
  2. 35
      tests/ImageSharp.Tests/MetaData/Profiles/Exif/ExifReaderTests.cs

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

@ -73,6 +73,8 @@ namespace ImageSharp
/// </returns>
public Collection<ExifValue> Read(byte[] data)
{
DebugGuard.NotNull(data, nameof(data));
Collection<ExifValue> result = new Collection<ExifValue>();
this.exifData = data;
@ -390,7 +392,13 @@ namespace ImageSharp
private string GetString(uint length)
{
return ToString(this.GetBytes(length));
byte[] data = this.GetBytes(length);
if (data == null || data.Length == 0)
{
return null;
}
return ToString(data);
}
private void GetThumbnail(uint offset)

35
tests/ImageSharp.Tests/MetaData/Profiles/Exif/ExifReaderTests.cs

@ -0,0 +1,35 @@
// <copyright file="ExifReaderTests.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageSharp.Tests
{
using System.Collections.ObjectModel;
using Xunit;
public class ExifReaderTests
{
[Fact]
public void Read_DataIsEmpty_ReturnsEmptyCollection()
{
ExifReader reader = new ExifReader();
byte[] data = new byte[] { };
Collection<ExifValue> result = reader.Read(data);
Assert.Equal(0, result.Count);
}
[Fact]
public void Read_DataIsMinimal_ReturnsEmptyCollection()
{
ExifReader reader = new ExifReader();
byte[] data = new byte[] { 69, 120, 105, 102, 0, 0 };
Collection<ExifValue> result = reader.Read(data);
Assert.Equal(0, result.Count);
}
}
}
Loading…
Cancel
Save