Browse Source

Ensure PutBitsFlushBits only writes 32 bits to the buffer

pull/1552/head
Brian Popow 6 years ago
parent
commit
d801ca8de2
  1. 9
      src/ImageSharp/Formats/WebP/BitWriter/Vp8LBitWriter.cs

9
src/ImageSharp/Formats/WebP/BitWriter/Vp8LBitWriter.cs

@ -13,6 +13,11 @@ namespace SixLabors.ImageSharp.Formats.WebP.BitWriter
/// </summary>
internal class Vp8LBitWriter : BitWriterBase
{
/// <summary>
/// A scratch buffer to reduce allocations.
/// </summary>
private readonly byte[] scratchBuffer = new byte[8];
/// <summary>
/// This is the minimum amount of size the memory buffer is guaranteed to grow when extra space is needed.
/// </summary>
@ -166,7 +171,9 @@ namespace SixLabors.ImageSharp.Formats.WebP.BitWriter
this.BitWriterResize(extraSize);
}
BinaryPrimitives.WriteUInt64LittleEndian(this.Buffer.AsSpan(this.cur), this.bits);
BinaryPrimitives.WriteUInt64LittleEndian(this.scratchBuffer, this.bits);
this.scratchBuffer.AsSpan(0, 4).CopyTo(this.Buffer.AsSpan(this.cur));
this.cur += WriterBytes;
this.bits >>= WriterBits;
this.used -= WriterBits;

Loading…
Cancel
Save