Browse Source
Merge pull request #1203 from SixLabors/js/hash-fix
Return input checksum value on empty buffer
pull/1574/head
James Jackson-South
6 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with
20 additions and
2 deletions
-
src/ImageSharp/Formats/Png/Zlib/Adler32.cs
-
src/ImageSharp/Formats/Png/Zlib/Crc32.cs
-
tests/ImageSharp.Tests/Formats/Png/Adler32Tests.cs
-
tests/ImageSharp.Tests/Formats/Png/Crc32Tests.cs
|
|
|
@ -59,7 +59,7 @@ namespace SixLabors.ImageSharp.Formats.Png.Zlib |
|
|
|
{ |
|
|
|
if (buffer.IsEmpty) |
|
|
|
{ |
|
|
|
return SeedValue; |
|
|
|
return adler; |
|
|
|
} |
|
|
|
|
|
|
|
#if SUPPORTS_RUNTIME_INTRINSICS
|
|
|
|
|
|
|
|
@ -57,7 +57,7 @@ namespace SixLabors.ImageSharp.Formats.Png.Zlib |
|
|
|
{ |
|
|
|
if (buffer.IsEmpty) |
|
|
|
{ |
|
|
|
return SeedValue; |
|
|
|
return crc; |
|
|
|
} |
|
|
|
|
|
|
|
#if SUPPORTS_RUNTIME_INTRINSICS
|
|
|
|
|
|
|
|
@ -10,6 +10,15 @@ namespace SixLabors.ImageSharp.Tests.Formats.Png |
|
|
|
{ |
|
|
|
public class Adler32Tests |
|
|
|
{ |
|
|
|
[Theory] |
|
|
|
[InlineData(0)] |
|
|
|
[InlineData(1)] |
|
|
|
[InlineData(2)] |
|
|
|
public void ReturnsCorrectWhenEmpty(uint input) |
|
|
|
{ |
|
|
|
Assert.Equal(input, Adler32.Calculate(input, default)); |
|
|
|
} |
|
|
|
|
|
|
|
[Theory] |
|
|
|
[InlineData(0)] |
|
|
|
[InlineData(8)] |
|
|
|
|
|
|
|
@ -10,6 +10,15 @@ namespace SixLabors.ImageSharp.Tests.Formats.Png |
|
|
|
{ |
|
|
|
public class Crc32Tests |
|
|
|
{ |
|
|
|
[Theory] |
|
|
|
[InlineData(0)] |
|
|
|
[InlineData(1)] |
|
|
|
[InlineData(2)] |
|
|
|
public void ReturnsCorrectWhenEmpty(uint input) |
|
|
|
{ |
|
|
|
Assert.Equal(input, Crc32.Calculate(input, default)); |
|
|
|
} |
|
|
|
|
|
|
|
[Theory] |
|
|
|
[InlineData(0)] |
|
|
|
[InlineData(8)] |
|
|
|
|