{"record":{"id":"68b128902fc1611f","repo":"apache/flink","slug":"malformed-input-around-byte-count","errorCode":null,"errorMessage":"malformed input around byte {count}","messagePattern":"malformed input around byte (.+?)","errorType":"exception","errorClass":"UTFDataFormatException","httpStatus":null,"severity":"error","filePath":"flink-core/src/main/java/org/apache/flink/core/memory/DataInputDeserializer.java","lineNumber":312,"sourceCode":"                case 4:\n                case 5:\n                case 6:\n                case 7:\n                    /* 0xxxxxxx */\n                    count++;\n                    chararr[chararrCount++] = (char) c;\n                    break;\n                case 12:\n                case 13:\n                    /* 110x xxxx 10xx xxxx */\n                    count += 2;\n                    if (count > utflen) {\n                        throw new UTFDataFormatException(\n                                \"malformed input: partial character at end\");\n                    }\n                    char2 = (int) bytearr[count - 1];\n                    if ((char2 & 0xC0) != 0x80) {\n                        throw new UTFDataFormatException(\"malformed input around byte \" + count);\n                    }\n                    chararr[chararrCount++] = (char) (((c & 0x1F) << 6) | (char2 & 0x3F));\n                    break;\n                case 14:\n                    /* 1110 xxxx 10xx xxxx 10xx xxxx */\n                    count += 3;\n                    if (count > utflen) {\n                        throw new UTFDataFormatException(\n                                \"malformed input: partial character at end\");\n                    }\n                    char2 = (int) bytearr[count - 2];\n                    char3 = (int) bytearr[count - 1];\n                    if (((char2 & 0xC0) != 0x80) || ((char3 & 0xC0) != 0x80)) {\n                        throw new UTFDataFormatException(\n                                \"malformed input around byte \" + (count - 1));\n                    }\n                    chararr[chararrCount++] =\n                            (char) (((c & 0x0F) << 12) | ((char2 & 0x3F) << 6) | (char3 & 0x3F));","sourceCodeStart":294,"sourceCodeEnd":330,"githubUrl":"https://github.com/apache/flink/blob/2f3c205e9266cb30240eb7f4fdab15cad629a70f/flink-core/src/main/java/org/apache/flink/core/memory/DataInputDeserializer.java#L294-L330","documentation":"Thrown while decoding a two-byte modified-UTF-8 character (cases 12/13). The lead byte was valid (110xxxxx) but the continuation byte (char2) does not have the required 10xxxxxx pattern (high two bits != 0x80 mask). The offending byte index is reported as 'around byte {count}'.","triggerScenarios":"readUTF()/readLongUTF() on data whose second byte of a 2-byte UTF sequence is malformed (e.g. 0xC3 followed by 0x41 instead of 0x80-0xBF).","commonSituations":"Raw standard UTF-8 mistakenly read where modified UTF-8 was expected (rare for the 2-byte range but possible); byte-level corruption from disk/network; a buffer overwritten by unrelated data; serializer version skew.","solutions":["Confirm writer and reader use the matched writeUTF/readUTF (or writeLongUTF/readLongUTF) encoding.","Inspect the raw bytes around the reported offset to confirm corruption vs. encoding mismatch.","For externally-produced bytes, decode with standard java.nio.charset UTF-8 instead of readUTF."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n    String s = input.readUTF();\n} catch (UTFDataFormatException e) {\n    // a 2-byte sequence had an invalid continuation byte\n    throw new IOException(\"Invalid modified-UTF-8 continuation: \" + e.getMessage(), e);\n}","preventionTips":["Never read standard-UTF-8 bytes with readUTF; decode with StandardCharsets.UTF_8 instead.","Use matched writeUTF/readUTF serialization on both sides.","Inspect bytes at the reported offset to confirm corruption vs. encoding mismatch."],"tags":["serialization","modified-utf-8","deserialization","corruption","string"],"backgroundTag":null,"analyzedSha":"2f3c205e9266cb30240eb7f4fdab15cad629a70f","analyzedAt":"2026-08-14T08:48:24.518Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}