BitReader.ReadByteArray() throws OverflowException when handling connection request
See original GitHub issueWhen a client is started and the server reacts to handle the connection request, it is throwing an OverflowException. See the exception stack trace below.
OverflowException: Arithmetic operation resulted in an overflow.
MLAPI.Serialization.BitReader.ReadByteArray (System.Byte[] readTo, System.Int64 knownLength) (at Assets/Third-Party/MLAPI/Serialization/BitReader.cs:781)
MLAPI.Messaging.InternalMessageHandler.HandleConnectionRequest (System.UInt64 clientId, System.IO.Stream stream) (at Assets/Third-Party/MLAPI/Messaging/InternalMessageHandler.cs:190)
MLAPI.NetworkingManager.HandleIncomingData (System.UInt64 clientId, System.String channelName, System.ArraySegment`1[T] data, System.Single receiveTime, System.Boolean allowBuffer) (at Assets/Third-Party/MLAPI/Core/NetworkingManager.cs:933)
MLAPI.NetworkingManager.HandleRawTransportPoll (MLAPI.Transports.NetEventType eventType, System.UInt64 clientId, System.String channelName, System.ArraySegment`1[T] payload, System.Single receiveTime) (at Assets/Third-Party/MLAPI/Core/NetworkingManager.cs:870)
MLAPI.NetworkingManager.Update () (at Assets/Third-Party/MLAPI/Core/NetworkingManager.cs:651)
Hooking up the debugger, I observed “knownLength” to be -1 after line 780, which I’m assuming is not expected ever. Feeding -1 into the array constructor produces the exception above.
Repro Steps
- Download the Bobble.zip Unity project
- Unzip and open the project in Unity 2019.4.12f1
- File > Build Settings… > Build a. Copy “AssetBundles” folder from root of Bobble project folder to build output folder b. Run Bobble.exe
- Open “Lobby” scene in Unity by navigating to Assets > Scenes > Lobby a. Enter play mode in the Editor
- At this point, you should have an instance of the Lobby scene running in the Editor and the built version a. Click “Start Host” in the Editor lobby b. Click “Join” in the Built lobby [BUG: see OverflowException in Editor console]
Expected Behavior I expect the client connection request data to be read without error.
Environment
- OS: Windows 10
- Unity Version: 2019.4
- MLAPI Version: v12.1.7 (sample project mentioned above uses source code from MLAPI commit https://github.com/Unity-Technologies/com.unity.multiplayer.mlapi/commit/e5e5729300981a9662d362ea9baa1b121d42d429 for debugger ease)
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (2 by maintainers)
Top Results From Across the Web
BitReader.ReadByteArray() throws OverflowException ...
When a client is started and the server reacts to handle the connection request, it is throwing an OverflowException.
Read more >Why is allocating a byte array throwing an Overflow ...
I am receiving an error on my C# Console Application. I am trying to do some code but its throwing an exception whenever...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Someone encountered this on Discord as well: https://discord.com/channels/449263083769036810/563033158480691211/815881188094640158
It looks like this exception (knownLength = -1) happens if the client has connection approval deactivated in the NetworkingManager while the server has it activated. On the server side MLAPI will try to read the length of the connection approval array but fail because the client didn’t write this into the stream at all.
Rebuilding the client/server after activating Connection Approval in the NetworkingManager should fix this issue.
I’m closing this under the assumption that the above helps resolving this issue. If that’s not the case please re-open it.
Hi Furic, I am currently looking into this bug and was hoping to get some more information regarding this issue. Looking at your Bobble.zip file, it appears that when you are joining as a client via the following method:
public void Join( string ipAddress, int port )
(NetworkLobby.cs) that theNetworkingManager.Singleton.NetworkConfig.ConnectionData
is never being populated with the “approval data/token” required to authenticate the connection request.MLAPI Documentation provides you with a basic example of how this might look, but I will run through your two methods used to start the client and the host and how it might look if you followed the MLAPI documentation example:
Client Side - within your
public void Join( string ipAddress, int port )
methodHost/Server Side - within your
void ConnectionApprovalCallback( byte[] data, ulong id, ConnectionApprovedDelegate callback )
method On the receiving side of things (i.e. Server), it would look like there is no code to check the passed in byte array value:Not knowing what kind of authorization/token information you will be populating the ConnectionData with, I am providing you with the “other end” of the authorization process that you would place just under the //TODO: disallow if client token is not valid:
Let me know if this solves your issue with connection authorization, and if it does not then if you could provide me with further information regarding where the NetworkingManager.Singleton.NetworkConfig.ConnectionData is being populated that would greatly help me further assist you.
Cheers, Noel