Skip to content

Commit 83101e8

Browse files
committed
Added some error handling around decompressing and extra logging.
1 parent f586557 commit 83101e8

1 file changed

Lines changed: 20 additions & 3 deletions

File tree

BPSR-ZDPSLib/NetCap.cs

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,10 @@ private void ParseFrameDown(ReadOnlySpan<byte> data, bool isCompressed, DateTime
270270
if (isCompressed)
271271
{
272272
var decompressed = Decompress(data[4..]);
273-
ParsePacket(decompressed, lastPacketTime);
273+
if (!decompressed.IsEmpty)
274+
{
275+
ParsePacket(decompressed, lastPacketTime);
276+
}
274277
}
275278
else
276279
{
@@ -288,6 +291,12 @@ private void ParseNotify(ReadOnlySpan<byte> data, bool isCompressed, DateTime la
288291
if (isCompressed)
289292
{
290293
msgData = Decompress(msgData);
294+
295+
if (msgData.IsEmpty)
296+
{
297+
Log.Logger.Warning("Error decompressing data for {serviceUuid}, {stubId}, {methodId}", serviceUuid, stubId, methodId);
298+
return;
299+
}
291300
}
292301

293302
if (!Enum.IsDefined(typeof(EServiceId), serviceUuid))
@@ -312,8 +321,16 @@ private void ParseNotify(ReadOnlySpan<byte> data, bool isCompressed, DateTime la
312321

313322
private ReadOnlySpan<byte> Decompress(ReadOnlySpan<byte> data)
314323
{
315-
var decompressedLen = _decompressor.Unwrap(data, DecompressionScratchBuffer);
316-
return DecompressionScratchBuffer.AsSpan()[..decompressedLen];
324+
try
325+
{
326+
var decompressedLen = _decompressor.Unwrap(data, DecompressionScratchBuffer.AsSpan());
327+
return DecompressionScratchBuffer.AsSpan()[..decompressedLen];
328+
}
329+
catch (Exception ex)
330+
{
331+
Log.Logger.Error(ex, "Error decompressing data of Len: {Len}, DecompressionScratchBuffer Size: {ScratchSize}", data.Length, DecompressionScratchBuffer.Length);
332+
return [];
333+
}
317334
}
318335

319336
private bool IsFromGame(IPv4Packet ip, TcpPacket tcp)

0 commit comments

Comments
 (0)