Skip to content

Commit 8df5efe

Browse files
authored
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
2 parents 3229351 + adf677a commit 8df5efe

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,10 @@ public void WriteTo(Stream stream)
123123
long pos = RiffHelper.BeginWriteChunk(stream, (uint)WebpChunkType.Vp8X);
124124

125125
stream.WriteByte(flags);
126-
stream.Position += 3; // Reserved bytes
126+
127+
Span<byte> reserved = stackalloc byte[3];
128+
stream.Write(reserved);
129+
127130
WebpChunkParsingUtils.WriteUInt24LittleEndian(stream, this.Width - 1);
128131
WebpChunkParsingUtils.WriteUInt24LittleEndian(stream, this.Height - 1);
129132

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Copyright (c) Six Labors.
2+
// Licensed under the Six Labors Split License.
3+
4+
using SixLabors.ImageSharp.Formats.Webp.Chunks;
5+
6+
namespace SixLabors.ImageSharp.Tests.Formats.WebP;
7+
8+
[Trait("Format", "Webp")]
9+
public class WebpVp8XTests
10+
{
11+
[Fact]
12+
public void WebpVp8X_WriteTo_Writes_Reserved_Bytes()
13+
{
14+
// arrange
15+
WebpVp8X header = new(false, false, false, false, false, 10, 40);
16+
MemoryStream ms = new();
17+
byte[] expected = [86, 80, 56, 88, 10, 0, 0, 0, 0, 0, 0, 0, 9, 0, 0, 39, 0, 0];
18+
19+
// act
20+
header.WriteTo(ms);
21+
22+
// assert
23+
byte[] actual = ms.ToArray();
24+
Assert.Equal(expected, actual);
25+
}
26+
}

0 commit comments

Comments
 (0)