Skip to content

Commit

Permalink
Validate proper implementation of bufferWriter to prevent overflows
Browse files Browse the repository at this point in the history
  • Loading branch information
brantburnett committed Dec 20, 2024
1 parent c0e5d27 commit e21e70d
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions Snappier/Internal/SnappyCompressor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,13 @@ private void CompressFragment(ReadOnlySpan<byte> fragment, IBufferWriter<byte> b
int maxOutput = Helpers.MaxCompressedLength(fragment.Length);

Span<byte> fragmentBuffer = bufferWriter.GetSpan(maxOutput);

// Validate proper implementation of bufferWriter to prevent buffer overflows
if (fragmentBuffer.Length < maxOutput)
{
ThrowHelper.ThrowInvalidOperationException("IBufferWriter<byte> did not return a sufficient span");
}

int bytesWritten = CompressFragment(fragment, fragmentBuffer, hashTable);
bufferWriter.Advance(bytesWritten);
}
Expand Down

0 comments on commit e21e70d

Please sign in to comment.