Skip to content

Commit 5e2a7cb

Browse files
Merge pull request #1203 from SixLabors/js/hash-fix
Return input checksum value on empty buffer
2 parents 4002a97 + 8a5072b commit 5e2a7cb

File tree

4 files changed

+20
-2
lines changed

4 files changed

+20
-2
lines changed

src/ImageSharp/Formats/Png/Zlib/Adler32.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public static uint Calculate(uint adler, ReadOnlySpan<byte> buffer)
5959
{
6060
if (buffer.IsEmpty)
6161
{
62-
return SeedValue;
62+
return adler;
6363
}
6464

6565
#if SUPPORTS_RUNTIME_INTRINSICS

src/ImageSharp/Formats/Png/Zlib/Crc32.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public static uint Calculate(uint crc, ReadOnlySpan<byte> buffer)
5757
{
5858
if (buffer.IsEmpty)
5959
{
60-
return SeedValue;
60+
return crc;
6161
}
6262

6363
#if SUPPORTS_RUNTIME_INTRINSICS

tests/ImageSharp.Tests/Formats/Png/Adler32Tests.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,15 @@ namespace SixLabors.ImageSharp.Tests.Formats.Png
1010
{
1111
public class Adler32Tests
1212
{
13+
[Theory]
14+
[InlineData(0)]
15+
[InlineData(1)]
16+
[InlineData(2)]
17+
public void ReturnsCorrectWhenEmpty(uint input)
18+
{
19+
Assert.Equal(input, Adler32.Calculate(input, default));
20+
}
21+
1322
[Theory]
1423
[InlineData(0)]
1524
[InlineData(8)]

tests/ImageSharp.Tests/Formats/Png/Crc32Tests.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,15 @@ namespace SixLabors.ImageSharp.Tests.Formats.Png
1010
{
1111
public class Crc32Tests
1212
{
13+
[Theory]
14+
[InlineData(0)]
15+
[InlineData(1)]
16+
[InlineData(2)]
17+
public void ReturnsCorrectWhenEmpty(uint input)
18+
{
19+
Assert.Equal(input, Crc32.Calculate(input, default));
20+
}
21+
1322
[Theory]
1423
[InlineData(0)]
1524
[InlineData(8)]

0 commit comments

Comments
 (0)