Skip to content

IndexOutOfRangeException in OSCPackerString.BytesToValue() #31

@ahihi

Description

@ahihi

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions