Browse Source

Merge pull request #3036 from jrlost/fix-3035

Fix VP8X reserved bytes use Position += 3 instead of Write, causing 3-byte truncation in alpha WebP images
pull/3040/head
Brian Popow 1 month ago
committed by GitHub
parent
commit
8df5efe3ad
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 5
      src/ImageSharp/Formats/Webp/Chunks/WebpVp8X.cs
  2. 26
      tests/ImageSharp.Tests/Formats/WebP/WebpVp8XTests.cs

5
src/ImageSharp/Formats/Webp/Chunks/WebpVp8X.cs

@ -123,7 +123,10 @@ internal readonly struct WebpVp8X : IEquatable<WebpVp8X>
long pos = RiffHelper.BeginWriteChunk(stream, (uint)WebpChunkType.Vp8X);
stream.WriteByte(flags);
stream.Position += 3; // Reserved bytes
Span<byte> reserved = stackalloc byte[3];
stream.Write(reserved);
WebpChunkParsingUtils.WriteUInt24LittleEndian(stream, this.Width - 1);
WebpChunkParsingUtils.WriteUInt24LittleEndian(stream, this.Height - 1);

26
tests/ImageSharp.Tests/Formats/WebP/WebpVp8XTests.cs

@ -0,0 +1,26 @@
// Copyright (c) Six Labors.
// Licensed under the Six Labors Split License.
using SixLabors.ImageSharp.Formats.Webp.Chunks;
namespace SixLabors.ImageSharp.Tests.Formats.WebP;
[Trait("Format", "Webp")]
public class WebpVp8XTests
{
[Fact]
public void WebpVp8X_WriteTo_Writes_Reserved_Bytes()
{
// arrange
WebpVp8X header = new(false, false, false, false, false, 10, 40);
MemoryStream ms = new();
byte[] expected = [86, 80, 56, 88, 10, 0, 0, 0, 0, 0, 0, 0, 9, 0, 0, 39, 0, 0];
// act
header.WriteTo(ms);
// assert
byte[] actual = ms.ToArray();
Assert.Equal(expected, actual);
}
}
Loading…
Cancel
Save