Skip to content

Commit 322e679

Browse files
author
Stefán Jökull Sigurðarson
committed
Some small code cleanups.
1 parent bf89fe7 commit 322e679

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

projects/RabbitMQ.Client/client/impl/Connection.Receive.cs

+6-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,12 @@ private async ValueTask MainLoopIteration()
9595

9696
if (buffer.First.Span[0] == 'A')
9797
{
98-
InboundFrame.ProcessProtocolHeader(buffer);
98+
if (buffer.Length >= 8)
99+
{
100+
InboundFrame.ProcessProtocolHeader(buffer);
101+
}
102+
103+
throw new EndOfStreamException("Invalid/truncated protocol header.");
99104
}
100105

101106
int framesRead = 0;

projects/RabbitMQ.Client/client/impl/Frame.cs

+2-7
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@
3232
using System;
3333
using System.Buffers;
3434
using System.Runtime.CompilerServices;
35-
using System.Runtime.InteropServices;
3635

3736
using RabbitMQ.Client.Exceptions;
3837
using RabbitMQ.Client.Framing.Impl;
38+
using RabbitMQ.Client.Logging;
3939
using RabbitMQ.Util;
4040

4141
namespace RabbitMQ.Client.Impl
@@ -245,6 +245,7 @@ public static bool TryParseInboundFrame(ref ReadOnlySequence<byte> buffer, out I
245245
}
246246

247247
buffer = buffer.Slice(frameSize);
248+
RabbitMqClientEventSource.Log.DataReceived(frameSize);
248249
FrameType frameType = (FrameType)payloadBytes[0];
249250
ushort channel = NetworkOrderDeserializer.ReadUInt16(ref Unsafe.AsRef(payloadBytes[1]));
250251
frame = new InboundFrame(frameType, channel, payloadBytes.AsMemory(7, payloadSize), payloadBytes);
@@ -256,12 +257,6 @@ private static bool ThrowMalformedFrameException(byte value)
256257
throw new MalformedFrameException($"Bad frame end marker: {value}");
257258
}
258259

259-
internal static InboundFrame ReadFrom(ReadOnlyMemory<byte> frameBytes)
260-
{
261-
MemoryMarshal.TryGetArray(frameBytes, out ArraySegment<byte> segment);
262-
return new InboundFrame((FrameType)frameBytes.Span[0], NetworkOrderDeserializer.ReadUInt16(frameBytes.Span.Slice(1)), frameBytes.Slice(7, frameBytes.Length - 8), segment.Array);
263-
}
264-
265260
public byte[] TakeoverPayload()
266261
{
267262
return _rentedArray;

0 commit comments

Comments
 (0)