0blu / PhotonPackageParser

A parser for Photon's Protocol16
MIT License
26 stars 17 forks source link

Exception thrown: 'System.IndexOutOfRangeException' in PhotonPackageParser.dll #11

Open Hecto-r opened 2 years ago

Hecto-r commented 2 years ago

try { var packet = Packet.ParsePacket(e.GetPacket().LinkLayerType, e.GetPacket().Data).Extract(); if (packet != null && (packet.SourcePort == 7656 || packet.DestinationPort == 7656)) { Console.WriteLine("packet: " + packet.PayloadData.Length); _receiver.ReceivePacket(packet.PayloadData); } } catch (Exception exc) { ConsoleManager.WriteLineForError(MethodBase.GetCurrentMethod()?.DeclaringType, exc); Log.Error(nameof(Device_OnPacketArrival), exc); } I've printed the lengths of the packet.PayloadData. This is the prints. packet: 58 Exception thrown: 'System.IndexOutOfRangeException' in PhotonPackageParser.dll packet: 44 Exception thrown: 'System.IndexOutOfRangeException' in PhotonPackageParser.dll packet: 236

Why is it throwing this exception?

Triky313 commented 2 years ago

Same problem here:

System.IndexOutOfRangeException: 'Index was outside the bounds of the array.' StackTrace = " at Protocol16.Photon.NumberDeserializer.Deserialize(Int32& value, Byte[] source, Int32& offset)\r\n at PhotonPackageParser.PhotonParser.HandleCommand(Byte[] source, Int32& offset)\r\n at PhotonPackageParser.PhotonParser.ReceivePacket(Byte[] payload)...

What can we do?

bonesoul commented 1 year ago

same here.

bonesoul commented 1 year ago

@Hecto-r @Triky313 were you able to fix the problem?

Triky313 commented 1 year ago

@bonesoul Nope. Just try catch. :/

toutouxue commented 1 year ago

i got a same problem,Can u send me some email or discord?

DocTi commented 1 year ago

Hello. This occurs when processing custom packages. They cannot be processed. The solution is try/catch at the parser call site.

toutouxue commented 1 year ago

i attempt to try/catch at the parser call site like this private void PacketHandler(object sender, CaptureEventArgs e) { try { UdpPacket packet = Packet.ParsePacket(e.Packet.LinkLayerType, e.Packet.Data).Extract(); if (packet != null && (packet.SourcePort == 43825 || packet.DestinationPort == 43825)) { photonParser.ReceivePacket(packet.PayloadData); } } catch (System.Exception) { System.Console.WriteLine(e); }
} but i cant go in to OnRequest or OnResponse that mean is the packages has change right?