Skip to content

Commit

Permalink
[release/6.0] Fixing a possible null reference error in WebSocket def…
Browse files Browse the repository at this point in the history
…late. (#62716)

* Fixing a possible null reference error in websocket deflate functionality.

* Style feedback.

Co-authored-by: Ivan Zlatanov <[email protected]>
  • Loading branch information
github-actions[bot] and zlatanov authored Dec 23, 2021
1 parent 818daa9 commit 67b110e
Showing 1 changed file with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -144,14 +144,21 @@ private unsafe void UnsafeDeflate(ReadOnlySpan<byte> input, Span<byte> output, o
consumed = input.Length - (int)_stream.AvailIn;
written = output.Length - (int)_stream.AvailOut;

needsMoreBuffer = errorCode == ErrorCode.BufError || _stream.AvailIn > 0;
// It is important here to also check that we haven't
// exhausted the output buffer because after deflating we're
// always going to issue a flush and a flush with empty output
// is going to throw.
needsMoreBuffer = errorCode == ErrorCode.BufError
|| _stream.AvailIn > 0
|| written == output.Length;
}
}

private unsafe int UnsafeFlush(Span<byte> output, out bool needsMoreBuffer)
{
Debug.Assert(_stream is not null);
Debug.Assert(_stream.AvailIn == 0);
Debug.Assert(output.Length > 0);

fixed (byte* fixedOutput = output)
{
Expand Down

0 comments on commit 67b110e

Please sign in to comment.