{"record":{"id":"ad8e62beaa19fac4","repo":"apache/flink","slug":"malformed-input-partial-character-at-end-ad8e62","errorCode":null,"errorMessage":"malformed input: partial character at end","messagePattern":"malformed input: partial character at end","errorType":"exception","errorClass":"UTFDataFormatException","httpStatus":null,"severity":"error","filePath":"flink-core/src/main/java/org/apache/flink/core/memory/DataInputDeserializer.java","lineNumber":307,"sourceCode":"            switch (c >> 4) {\n                case 0:\n                case 1:\n                case 2:\n                case 3:\n                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)) {","sourceCodeStart":289,"sourceCodeEnd":325,"githubUrl":"https://github.com/apache/flink/blob/2f3c205e9266cb30240eb7f4fdab15cad629a70f/flink-core/src/main/java/org/apache/flink/core/memory/DataInputDeserializer.java#L289-L325","documentation":"Thrown while decoding a modified-UTF-8 string in readString (called by readUTF/readLongUTF). A two-byte sequence (lead byte 110xxxxx, cases 12/13) was started but advancing count by 2 overshoots the declared utflen, meaning the declared byte length was too short to hold the trailing character. This signals truncated or corrupted serialized string data.","triggerScenarios":"readUTF() or readLongUTF() on a buffer whose UTF length prefix declares fewer bytes than the multi-byte character at that position requires; e.g. utflen ends mid-character after a 0xC0-0xDF lead byte.","commonSituations":"Serializer mismatch between the writer and reader; truncated checkpoint/state/network data; a byte buffer that was sliced before the full string was written; hand-crafted byte arrays that don't follow Java modified UTF-8.","solutions":["Ensure the same serializer (writeUTF/readUTF or writeLongUTF/readLongUTF pair) is used on both sides.","Verify the buffer was fully populated before decoding (available() >= utflen + lengthPrefixSize).","If data is untrusted or persisted across versions, wrap readUTF in try/catch UTFDataFormatException and treat as schema/state corruption."],"exampleFix":"// before\nString s = input.readUTF();\n\n// after\ntry {\n    String s = input.readUTF();\n} catch (UTFDataFormatException e) {\n    throw new IOException(\"Corrupted serialized string: \" + e.getMessage(), e);\n}","handlingStrategy":"try-catch","validationCode":"int declared = input.available();\n// readUTF reads an unsigned short length prefix, then that many bytes\nif (declared < 2) {\n    throw new EOFException(\"Not enough bytes for UTF length prefix\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    String s = input.readUTF();\n} catch (UTFDataFormatException e) {\n    // corrupted/truncated serialized string: surface as state/schema corruption\n    throw new IOException(\"Corrupted UTF string: \" + e.getMessage(), e);\n}","preventionTips":["Always pair writeUTF with readUTF (and writeLongUTF with readLongUTF).","Keep the same TypeSerializer version on writer and reader sides.","Treat UTFDataFormatException as data corruption and isolate the affected record/partition."],"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"}