diff --git a/Snappier/Internal/SnappyCompressor.cs b/Snappier/Internal/SnappyCompressor.cs index 7a4c16f..7e7fa75 100644 --- a/Snappier/Internal/SnappyCompressor.cs +++ b/Snappier/Internal/SnappyCompressor.cs @@ -149,6 +149,13 @@ private void CompressFragment(ReadOnlySpan fragment, IBufferWriter b int maxOutput = Helpers.MaxCompressedLength(fragment.Length); Span fragmentBuffer = bufferWriter.GetSpan(maxOutput); + + // Validate proper implementation of bufferWriter to prevent buffer overflows + if (fragmentBuffer.Length < maxOutput) + { + ThrowHelper.ThrowInvalidOperationException("IBufferWriter did not return a sufficient span"); + } + int bytesWritten = CompressFragment(fragment, fragmentBuffer, hashTable); bufferWriter.Advance(bytesWritten); }