Skip to content

Commit 67b110e

Browse files
[release/6.0] Fixing a possible null reference error in WebSocket deflate. (#62716)
* Fixing a possible null reference error in websocket deflate functionality. * Style feedback. Co-authored-by: Ivan Zlatanov <[email protected]>
1 parent 818daa9 commit 67b110e

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/libraries/System.Net.WebSockets/src/System/Net/WebSockets/Compression/WebSocketDeflater.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,14 +144,21 @@ private unsafe void UnsafeDeflate(ReadOnlySpan<byte> input, Span<byte> output, o
144144
consumed = input.Length - (int)_stream.AvailIn;
145145
written = output.Length - (int)_stream.AvailOut;
146146

147-
needsMoreBuffer = errorCode == ErrorCode.BufError || _stream.AvailIn > 0;
147+
// It is important here to also check that we haven't
148+
// exhausted the output buffer because after deflating we're
149+
// always going to issue a flush and a flush with empty output
150+
// is going to throw.
151+
needsMoreBuffer = errorCode == ErrorCode.BufError
152+
|| _stream.AvailIn > 0
153+
|| written == output.Length;
148154
}
149155
}
150156

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

156163
fixed (byte* fixedOutput = output)
157164
{

0 commit comments

Comments
 (0)