Skip to content

Commit 0cbf475

Browse files
Merge pull request #2676 from SixLabors/js/fix-2670
Fix AccessViolationException and hard crash with animated webp
2 parents 9c9854d + f6d24ed commit 0cbf475

File tree

4 files changed

+18
-6
lines changed

4 files changed

+18
-6
lines changed

src/ImageSharp/Formats/Webp/AlphaDecoder.cs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -311,18 +311,15 @@ private static void ColorIndexInverseTransformAlpha(
311311

312312
private static void HorizontalUnfilter(Span<byte> prev, Span<byte> input, Span<byte> dst, int width)
313313
{
314-
if (Sse2.IsSupported)
314+
// TODO: Investigate AdvSimd support for this method.
315+
if (Sse2.IsSupported && width >= 9)
315316
{
316317
dst[0] = (byte)(input[0] + (prev.IsEmpty ? 0 : prev[0]));
317-
if (width <= 1)
318-
{
319-
return;
320-
}
321-
322318
nuint i;
323319
Vector128<int> last = Vector128<int>.Zero.WithElement(0, dst[0]);
324320
ref byte srcRef = ref MemoryMarshal.GetReference(input);
325321
ref byte dstRef = ref MemoryMarshal.GetReference(dst);
322+
326323
for (i = 1; i <= (uint)width - 8; i += 8)
327324
{
328325
Vector128<long> a0 = Vector128.Create(Unsafe.As<byte, long>(ref Unsafe.Add(ref srcRef, i)), 0);

tests/ImageSharp.Tests/Formats/WebP/WebpDecoderTests.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,17 @@ public void WebpDecoder_CanDecode_Issue2257<TPixel>(TestImageProvider<TPixel> pr
439439
image.CompareToOriginal(provider, ReferenceDecoder);
440440
}
441441

442+
// https://github.com/SixLabors/ImageSharp/issues/2670
443+
[Theory]
444+
[WithFile(Lossy.Issue2670, PixelTypes.Rgba32)]
445+
public void WebpDecoder_CanDecode_Issue2670<TPixel>(TestImageProvider<TPixel> provider)
446+
where TPixel : unmanaged, IPixel<TPixel>
447+
{
448+
using Image<TPixel> image = provider.GetImage(WebpDecoder.Instance);
449+
image.DebugSave(provider);
450+
image.CompareToOriginal(provider, ReferenceDecoder);
451+
}
452+
442453
[Theory]
443454
[WithFile(Lossless.LossLessCorruptImage3, PixelTypes.Rgba32)]
444455
public void WebpDecoder_ThrowImageFormatException_OnInvalidImages<TPixel>(TestImageProvider<TPixel> provider)

tests/ImageSharp.Tests/TestImages.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -804,6 +804,7 @@ public static class Lossy
804804
public const string Issue1594 = "Webp/issues/Issue1594.webp";
805805
public const string Issue2243 = "Webp/issues/Issue2243.webp";
806806
public const string Issue2257 = "Webp/issues/Issue2257.webp";
807+
public const string Issue2670 = "Webp/issues/Issue2670.webp";
807808
}
808809
}
809810

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version https://git-lfs.github.com/spec/v1
2+
oid sha256:23ad5eb449f693af68e51dd108a6b9847a8eb48b82ca5b848395a54c2e0be08f
3+
size 152

0 commit comments

Comments
 (0)