Skip to content

Commit c55e631

Browse files
committed
fix BrotliCompressor
1 parent f30eb95 commit c55e631

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

Diff for: src/MemoryPack.Core/Compression/BrotliCompressor.cs

+3-1
Original file line numberDiff line numberDiff line change
@@ -262,9 +262,11 @@ static int CompressCore<TBufferWriter>(ref BrotliEncoder encoder, ReadOnlySpan<b
262262
var totalWritten = 0;
263263

264264
var lastResult = OperationStatus.DestinationTooSmall;
265+
266+
var destLength = initialLength ?? BrotliUtils.BrotliEncoderMaxCompressedSize(source.Length);
265267
while (lastResult == OperationStatus.DestinationTooSmall)
266268
{
267-
ref var spanRef = ref destBufferWriter.GetSpanReference(initialLength ?? source.Length);
269+
ref var spanRef = ref destBufferWriter.GetSpanReference(destLength);
268270
var dest = MemoryMarshal.CreateSpan(ref spanRef, destBufferWriter.BufferLength);
269271

270272
lastResult = encoder.Compress(source, dest, out int bytesConsumed, out int bytesWritten, isFinalBlock: isFinalBlock);

0 commit comments

Comments
 (0)