Skip to content

Commit

Permalink
Ensure we account for packets having more data than expected
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-r-elp committed Jul 27, 2024
1 parent cbe1fd0 commit d196b46
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions BeatTogether.DedicatedServer.Kernel/PacketSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,11 @@ public void OnReceive(EndPoint remoteEndPoint, ref SpanBuffer reader, IgnoranceC
continue;
}

// Ensure we always skip/rewind our reader
var processedBytesToSkip = HandleRead.Offset - prevPosition;
try { HandleRead.SkipBytes((int)length - processedBytesToSkip); }
catch (EndOfBufferException) { _logger.Warning("Packet was an incorrect length"); goto RoutePacket; }

((Abstractions.IPacketHandler)packetHandler).Handle(sender, packet);
}
RoutePacket:
Expand Down

0 comments on commit d196b46

Please sign in to comment.