From 2edab61535c53ae9c665b931c78fcf77cc55407c Mon Sep 17 00:00:00 2001 From: John Fredrickson Date: Tue, 23 Dec 2025 13:31:23 -0600 Subject: [PATCH 1/2] Write into stream instead of simply just advancing it. --- src/ImageSharp/Formats/Webp/Chunks/WebpVp8X.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/ImageSharp/Formats/Webp/Chunks/WebpVp8X.cs b/src/ImageSharp/Formats/Webp/Chunks/WebpVp8X.cs index 491f71650..7cec7c1db 100644 --- a/src/ImageSharp/Formats/Webp/Chunks/WebpVp8X.cs +++ b/src/ImageSharp/Formats/Webp/Chunks/WebpVp8X.cs @@ -123,7 +123,10 @@ internal readonly struct WebpVp8X : IEquatable long pos = RiffHelper.BeginWriteChunk(stream, (uint)WebpChunkType.Vp8X); stream.WriteByte(flags); - stream.Position += 3; // Reserved bytes + + Span reserved = stackalloc byte[3]; + stream.Write(reserved); + WebpChunkParsingUtils.WriteUInt24LittleEndian(stream, this.Width - 1); WebpChunkParsingUtils.WriteUInt24LittleEndian(stream, this.Height - 1); From adf677a829590b02a72753e741506b9615c635c5 Mon Sep 17 00:00:00 2001 From: Brian Popow Date: Sun, 28 Dec 2025 17:25:08 +0100 Subject: [PATCH 2/2] Add test for writing reserved bytes in WebpVp8X --- .../Formats/WebP/WebpVp8XTests.cs | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 tests/ImageSharp.Tests/Formats/WebP/WebpVp8XTests.cs diff --git a/tests/ImageSharp.Tests/Formats/WebP/WebpVp8XTests.cs b/tests/ImageSharp.Tests/Formats/WebP/WebpVp8XTests.cs new file mode 100644 index 000000000..78be0bf9f --- /dev/null +++ b/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); + } +}