{"record":{"id":"f55ae3e760573d52","repo":"Unity-Technologies/UnityCsReference","slug":"received-corrupted-message","errorCode":null,"errorMessage":"Received corrupted message","messagePattern":"Received corrupted message","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"Editor/Mono/PlayerConnectionLogReceiver.cs","lineNumber":137,"sourceCode":"\n            var name = ConnectionUIHelper.GetPlayerNameFromId(messageEventArgs.playerId);\n            var t = ConnectionUIHelper.GetPlayerType(ProfilerDriver.GetConnectionIdentifier(messageEventArgs.playerId));\n\n            var messagePrefix = $\"<i>{t} \\\"{name}\\\"</i> \";\n            var prefixUtf8Bytes = Encoding.UTF8.GetBytes(messagePrefix);\n\n            fixed (byte* payloadPtr = messageEventArgs.data.AsSpan<byte>())\n            fixed (byte* prefixUtf8Ptr = prefixUtf8Bytes)\n            {\n                static UTF8StringView ReadString(byte* payload, ref int offset)\n                {\n                    var bytesLength = BitConverter.ToInt32(new ReadOnlySpan<byte>(payload + offset, 4));\n                    offset += 4;\n\n                    if (bytesLength == 0)\n                        return default;\n                    if (bytesLength < 0)\n                        throw new Exception(\"Received corrupted message\");\n\n                    var utf8StringPtr = payload + offset;\n                    offset += bytesLength;\n                    return new UTF8StringView(utf8StringPtr, bytesLength);\n                }\n\n                static LogMessageFlags FlagsFromType(LogType type)\n                {\n                    switch (type)\n                    {\n                        case LogType.Warning: return LogMessageFlags.DebugWarning;\n                        case LogType.Error: return LogMessageFlags.DebugError;\n                        case LogType.Assert: return LogMessageFlags.DebugAssert;\n                        case LogType.Exception: return LogMessageFlags.DebugException;\n                    }\n                    return LogMessageFlags.DebugLog;\n                }\n","sourceCodeStart":119,"sourceCodeEnd":155,"githubUrl":"https://github.com/Unity-Technologies/UnityCsReference/blob/225b0fbdb57cc17d094e8056b71f8314aba56f73/Editor/Mono/PlayerConnectionLogReceiver.cs#L119-L155","documentation":"Thrown by the ReadString helper inside PlayerConnectionLogReceiver.LogMessageMultiple when deserializing a log message payload from a connected player and the byte-length prefix of a string field is negative. A negative length indicates the payload is malformed or corrupted — either truncated, byte-misaligned, or from an incompatible player/editor protocol version. The method reads log type, message, timestamp, and stacktrace strings sequentially from the payload buffer.","triggerScenarios":"A connected player (via Player Connection / Profiler connection) sends a log message batch whose binary payload is corrupted or uses an incompatible serialization format. The ReadString function reads a 4-byte Int32 length prefix; if that value is negative, the payload is unrecoverable.","commonSituations":"Connecting a player built with a different Unity version than the editor; network corruption or packet loss on the player connection; player crash mid-transmission producing a truncated payload; debugging a custom player connection protocol that sends malformed data.","solutions":["Ensure the connected player is built with the same Unity version as the editor to avoid protocol mismatches.","Check the player connection network stability — unstable connections can produce truncated payloads.","If developing a custom connection, verify your binary payload matches the expected format (4-byte Int32 length prefix per string field, in order: logType, message, timestamp, stacktrace)."],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":["Build players with the same Unity version as the editor to avoid protocol mismatches.","Ensure network stability for player connections — unstable links produce truncated payloads.","Validate custom player connection payloads match the expected binary format before sending."],"tags":["unity-editor","player-connection","network","deserialization","data-corruption"],"backgroundTag":null,"analyzedSha":"225b0fbdb57cc17d094e8056b71f8314aba56f73","analyzedAt":"2026-08-13T19:07:19.849Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}