diff --git a/appveyor.yml b/appveyor.yml
index f784ef2876..9b1ce2b958 100644
--- a/appveyor.yml
+++ b/appveyor.yml
@@ -1,5 +1,5 @@
version: 1.0.0.{build}
-image: Visual Studio 2017
+image: Visual Studio 2017 Preview
# prevent the double build when a branch has an active PR
skip_branch_with_pr: true
diff --git a/src/ImageSharp/Formats/Png/Filters/NoneFilter.cs b/src/ImageSharp/Formats/Png/Filters/NoneFilter.cs
index 14af8ca6a0..97e16ef233 100644
--- a/src/ImageSharp/Formats/Png/Filters/NoneFilter.cs
+++ b/src/ImageSharp/Formats/Png/Filters/NoneFilter.cs
@@ -3,7 +3,6 @@
using System;
using System.Runtime.CompilerServices;
-using SixLabors.ImageSharp.Memory;
namespace SixLabors.ImageSharp.Formats.Png.Filters
{
@@ -25,7 +24,7 @@ namespace SixLabors.ImageSharp.Formats.Png.Filters
// Insert a byte before the data.
result[0] = 0;
result = result.Slice(1);
- SpanHelper.Copy(scanline, result);
+ scanline.Slice(0, Math.Min(scanline.Length, result.Length)).CopyTo(result);
}
}
-}
+}
\ No newline at end of file
diff --git a/src/ImageSharp/Memory/SpanHelper.cs b/src/ImageSharp/Memory/SpanHelper.cs
deleted file mode 100644
index 592e2a885b..0000000000
--- a/src/ImageSharp/Memory/SpanHelper.cs
+++ /dev/null
@@ -1,48 +0,0 @@
-// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
-
-using System;
-using System.Runtime.CompilerServices;
-
-namespace SixLabors.ImageSharp.Memory
-{
- ///
- /// Utility methods for
- ///
- internal static class SpanHelper
- {
- ///
- /// Copy all elements of 'source' into 'destination'.
- ///
- /// The element type.
- /// The to copy elements from.
- /// The destination .
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static void Copy(ReadOnlySpan source, Span destination)
- where T : struct
- {
- source.Slice(0, Math.Min(source.Length, destination.Length)).CopyTo(destination);
- }
-
- ///
- /// Gets the size of `count` elements in bytes.
- ///
- /// The element type.
- /// The count of the elements
- /// The size in bytes as int
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static int SizeOf(int count)
- where T : struct => Unsafe.SizeOf() * count;
-
- ///
- /// Gets the size of `count` elements in bytes as UInt32
- ///
- /// The element type.
- /// The count of the elements
- /// The size in bytes as UInt32
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static uint USizeOf(int count)
- where T : struct
- => (uint)SizeOf(count);
- }
-}
\ No newline at end of file
diff --git a/src/ImageSharp/MetaData/Profiles/Exif/ExifReader.cs b/src/ImageSharp/MetaData/Profiles/Exif/ExifReader.cs
index c00eec6010..4f28449d64 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;
}
diff --git a/tests/ImageSharp.Tests/ConfigurationTests.cs b/tests/ImageSharp.Tests/ConfigurationTests.cs
index 88aabfe337..d870b7bf78 100644
--- a/tests/ImageSharp.Tests/ConfigurationTests.cs
+++ b/tests/ImageSharp.Tests/ConfigurationTests.cs
@@ -1,95 +1,95 @@
-// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
-
-using System;
-using System.Collections.Generic;
-using System.IO;
-using System.Linq;
-using SixLabors.ImageSharp.Formats;
-using SixLabors.ImageSharp.IO;
-using SixLabors.ImageSharp.PixelFormats;
-using Moq;
-using Xunit;
-
-namespace SixLabors.ImageSharp.Tests
-{
- ///
- /// Tests the configuration class.
- ///
- public class ConfigurationTests
- {
- public Configuration ConfigurationEmpty { get; private set; }
- public Configuration DefaultConfiguration { get; private set; }
-
- public ConfigurationTests()
- {
- // the shallow copy of configuration should behave exactly like the default configuration,
- // so by using the copy, we test both the default and the copy.
- this.DefaultConfiguration = Configuration.CreateDefaultInstance().ShallowCopy();
- this.ConfigurationEmpty = new Configuration();
- }
-
- [Fact]
- public void DefaultsToLocalFileSystem()
- {
- Assert.IsType(this.DefaultConfiguration.FileSystem);
- Assert.IsType(this.ConfigurationEmpty.FileSystem);
- }
-
- ///
- /// Test that the default configuration is not null.
- ///
- [Fact]
- public void TestDefultConfigurationIsNotNull()
- {
- Assert.True(Configuration.Default != null);
- }
-
- ///
- /// Test that the default configuration parallel options is not null.
- ///
- [Fact]
- public void TestDefultConfigurationParallelOptionsIsNotNull()
- {
- Assert.True(Configuration.Default.ParallelOptions != null);
- }
-
- ///
- /// Test that the default configuration read origin options is set to begin.
- ///
- [Fact]
- public void TestDefultConfigurationReadOriginIsCurrent()
- {
- Assert.True(Configuration.Default.ReadOrigin == ReadOrigin.Current);
- }
-
- ///
- /// Test that the default configuration parallel options max degrees of parallelism matches the
- /// environment processor count.
- ///
- [Fact]
- public void TestDefultConfigurationMaxDegreeOfParallelism()
- {
- Assert.True(Configuration.Default.ParallelOptions.MaxDegreeOfParallelism == Environment.ProcessorCount);
- }
-
- [Fact]
- public void ConstructorCallConfigureOnFormatProvider()
- {
- var provider = new Mock();
- var config = new Configuration(provider.Object);
-
- provider.Verify(x => x.Configure(config));
- }
-
- [Fact]
- public void AddFormatCallsConfig()
- {
- var provider = new Mock();
- var config = new Configuration();
- config.Configure(provider.Object);
-
- provider.Verify(x => x.Configure(config));
- }
- }
+// Copyright (c) Six Labors and contributors.
+// Licensed under the Apache License, Version 2.0.
+
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using SixLabors.ImageSharp.Formats;
+using SixLabors.ImageSharp.IO;
+using SixLabors.ImageSharp.PixelFormats;
+using Moq;
+using Xunit;
+
+namespace SixLabors.ImageSharp.Tests
+{
+ ///
+ /// Tests the configuration class.
+ ///
+ public class ConfigurationTests
+ {
+ public Configuration ConfigurationEmpty { get; private set; }
+ public Configuration DefaultConfiguration { get; private set; }
+
+ public ConfigurationTests()
+ {
+ // the shallow copy of configuration should behave exactly like the default configuration,
+ // so by using the copy, we test both the default and the copy.
+ this.DefaultConfiguration = Configuration.CreateDefaultInstance().ShallowCopy();
+ this.ConfigurationEmpty = new Configuration();
+ }
+
+ [Fact]
+ public void DefaultsToLocalFileSystem()
+ {
+ Assert.IsType(this.DefaultConfiguration.FileSystem);
+ Assert.IsType(this.ConfigurationEmpty.FileSystem);
+ }
+
+ ///
+ /// Test that the default configuration is not null.
+ ///
+ [Fact]
+ public void TestDefaultConfigurationIsNotNull()
+ {
+ Assert.True(Configuration.Default != null);
+ }
+
+ ///
+ /// Test that the default configuration parallel options is not null.
+ ///
+ [Fact]
+ public void TestDefaultConfigurationParallelOptionsIsNotNull()
+ {
+ Assert.True(Configuration.Default.ParallelOptions != null);
+ }
+
+ ///
+ /// Test that the default configuration read origin options is set to begin.
+ ///
+ [Fact]
+ public void TestDefaultConfigurationReadOriginIsCurrent()
+ {
+ Assert.True(Configuration.Default.ReadOrigin == ReadOrigin.Current);
+ }
+
+ ///
+ /// Test that the default configuration parallel options max degrees of parallelism matches the
+ /// environment processor count.
+ ///
+ [Fact]
+ public void TestDefaultConfigurationMaxDegreeOfParallelism()
+ {
+ Assert.True(Configuration.Default.ParallelOptions.MaxDegreeOfParallelism == Environment.ProcessorCount);
+ }
+
+ [Fact]
+ public void ConstructorCallConfigureOnFormatProvider()
+ {
+ var provider = new Mock();
+ var config = new Configuration(provider.Object);
+
+ provider.Verify(x => x.Configure(config));
+ }
+
+ [Fact]
+ public void AddFormatCallsConfig()
+ {
+ var provider = new Mock();
+ var config = new Configuration();
+ config.Configure(provider.Object);
+
+ provider.Verify(x => x.Configure(config));
+ }
+ }
}
\ No newline at end of file
diff --git a/tests/ImageSharp.Tests/MetaData/Profiles/Exif/ExifProfileTests.cs b/tests/ImageSharp.Tests/MetaData/Profiles/Exif/ExifProfileTests.cs
index d98c61279b..3c69b57fd2 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 85f12bc808..d261f94974 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 0000000000..bf7c4c72a4
Binary files /dev/null and b/tests/Images/Input/Jpg/issues/Issue520-InvalidCast.jpg differ