Skip to content
This repository was archived by the owner on Jan 25, 2026. It is now read-only.

Commit ccbdd53

Browse files
committed
fix(McPing): 获取到的数据长度信息错误
1 parent 350ba43 commit ccbdd53

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

Utils/Minecraft/McPing.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,10 @@ public async Task<McPingResult> PingAsync()
7777

7878
_socket.Close();
7979
var retBinary = res.ToArray();
80-
var packId = VarInt.Decode(retBinary.Skip(1).ToArray(), out var packIdLength);
81-
LogWrapper.Debug("McPing",$"PackId: {packId}, PackIdLength: {packIdLength}");
82-
var retCtx = Encoding.UTF8.GetString([.. retBinary.Skip(1 + packIdLength)]);
80+
var dataLength = Convert.ToInt32(VarInt.Decode(retBinary.Skip(1).ToArray(), out var packDataHeaderLength));
81+
LogWrapper.Debug("McPing",$"ServerDataLength: {dataLength}");
82+
if (dataLength > retBinary.Length) throw new Exception("The server data is too large");
83+
var retCtx = Encoding.UTF8.GetString([.. retBinary.Skip(1 + packDataHeaderLength).Take(dataLength)]);
8384
#if DEBUG
8485
LogWrapper.Debug("McPing", retCtx);
8586
#endif

0 commit comments

Comments
 (0)