Skip to content

Commit 473192e

Browse files
committed
fix NUL frame parsing
1 parent 0a024c5 commit 473192e

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

src/RESPite/Messages/RespFrameScanner.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
using System.Buffers;
22
using System.Diagnostics.CodeAnalysis;
3+
using System.Runtime.CompilerServices;
4+
using System.Runtime.InteropServices;
35
using static RESPite.Internal.RespConstants;
46
namespace RESPite.Messages;
57

@@ -52,7 +54,11 @@ private static OperationStatus TryFastRead(ReadOnlySpan<byte> data, ref RespScan
5254
case 2:
5355
return OperationStatus.NeedMoreData;
5456
case 3:
55-
hi = (((uint)UnsafeCpuUInt16(data)) << 16) | (((uint)UnsafeCpuByte(data, 2)) << 8);
57+
hi = 0; // needed to wipe that final byte
58+
Unsafe.CopyBlock(
59+
ref Unsafe.As<uint, byte>(ref hi),
60+
ref MemoryMarshal.GetReference(data),
61+
3);
5662
break;
5763
default:
5864
hi = UnsafeCpuUInt32(data);

0 commit comments

Comments
 (0)