Iam1337 / extOSC

extOSC is a tool dedicated to simplify creation of applications in Unity with OSC protocol usage.
MIT License
193 stars 25 forks source link

IndexOutOfRangeException in OSCPackerString.BytesToValue() #31

Closed ahihi closed 7 months ago

ahihi commented 9 months ago

with OSCReceiver, receiving OSCMessages of the form /orientation/supperware/quaternion 0.9975586 0.06152344 -0.01367188 -0.01708984 throws:

[OSCReceiver] Receive error: System.IndexOutOfRangeException: Index was outside the bounds of the array.
  at extOSC.Core.Packers.OSCPackerString.BytesToValue (System.Byte[] buffer, System.Int32& index) [0x00012] in [...]/Assets/extOSC/Scripts/Core/Packers/OSCPackerString.cs:23 
  at extOSC.Core.Packers.OSCPacker`1[T].Unpack (System.Byte[] bytes, System.Int32& start) [0x00001] in [...]/Assets/extOSC/Scripts/Core/Packers/OSCPacker.cs:38 
  at extOSC.Core.OSCConverter.UnpackValue (extOSC.OSCValueType valueType, System.Byte[] bytes, System.Int32& start) [0x00035] in [...]/Assets/extOSC/Scripts/Core/OSCConverter.cs:349 
  at extOSC.Core.OSCConverter.UnpackMessage (System.Byte[] bytes, System.Int32& start) [0x00011] in [...]/Assets/extOSC/Scripts/Core/OSCConverter.cs:282 
  at extOSC.Core.OSCConverter.UnpackInternal (System.Byte[] bytes, System.Int32& start, System.Int32 end) [0x00017] in [...]/Assets/extOSC/Scripts/Core/OSCConverter.cs:250 
  at extOSC.Core.OSCConverter.Unpack (System.Byte[] buffer, System.Int32 length) [0x00015] in [...]/Assets/extOSC/Scripts/Core/OSCConverter.cs:136 
  at extOSC.Core.OSCConverter.Unpack (System.Byte[] bytes) [0x00013] in [...]/Assets/extOSC/Scripts/Core/OSCConverter.cs:127 
  at extOSC.Core.Network.OSCReceiverStandaloneBackend.Receive (System.Net.Sockets.UdpClient receivedClient, System.IAsyncResult result) [0x0001e] in [...]/Assets/extOSC/Scripts/Core/Network/OSCReceiverStandaloneBackend.cs:137 
UnityEngine.Debug:LogError (object)
extOSC.Core.Network.OSCReceiverStandaloneBackend:Receive (System.Net.Sockets.UdpClient,System.IAsyncResult) (at Assets/extOSC/Scripts/Core/Network/OSCReceiverStandaloneBackend.cs:151)
extOSC.Core.Network.OSCReceiverStandaloneBackend:ControllerThread (System.IAsyncResult) (at Assets/extOSC/Scripts/Core/Network/OSCReceiverStandaloneBackend.cs:110)
System.Threading._ThreadPoolWaitCallback:PerformWaitCallback ()

the line in question is:

while (buffer[position] != 0 && position < buffer.Length)

i dont know exactly how we get here, but at the time of the exception we have position == buffer.Length. perhaps the position < buffer.Length check is meant to guard against this, but of course it does not help since it happens after the invalid indexing.

swapping the conditions to:

while (position < buffer.Length && buffer[position] != 0)

seems to fix it.

Iam1337 commented 7 months ago

Hi! I apologize very much for such a late response. I will fix this error soon as possibly.

Iam1337 commented 7 months ago

Fixed in c9622a8a97e19dbe86d86551cf589d93c803e9a3. Thanks!