{"record":{"id":"8710e0b5186777af","repo":"apache/flink","slug":"malformed-input-around-byte-count-1","errorCode":null,"errorMessage":"malformed input around byte {count-1}","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":326,"sourceCode":"                                \"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));\n                    break;\n                default:\n                    /* 10xx xxxx, 1111 xxxx */\n                    throw new UTFDataFormatException(\"malformed input around byte \" + count);\n            }\n        }\n        // The number of chars produced may be less than utflen\n        return new String(chararr, 0, chararrCount);\n    }\n\n    @Override\n    public int readUnsignedByte() throws IOException {\n        if (this.position < this.end) {\n            return (this.buffer[this.position++] & 0xff);","sourceCodeStart":308,"sourceCodeEnd":344,"githubUrl":"https://github.com/apache/flink/blob/2f3c205e9266cb30240eb7f4fdab15cad629a70f/flink-core/src/main/java/org/apache/flink/core/memory/DataInputDeserializer.java#L308-L344","documentation":"Thrown while decoding a three-byte modified-UTF-8 character (case 14). The lead byte was valid (1110xxxx) but at least one of the two continuation bytes (char2, char3) lacks the required 10xxxxxx pattern. The byte index reported is 'around byte {count-1}'.","triggerScenarios":"readUTF()/readLongUTF() on data where a 3-byte sequence's continuation byte(s) are malformed (not in 0x80-0xBF).","commonSituations":"Byte corruption in multi-byte (non-ASCII) string regions; encoding mismatch (standard UTF-8 vs modified UTF-8); buffer overwritten; serializer version skew affecting string state.","solutions":["Inspect raw bytes at the reported offset to distinguish corruption from encoding mismatch.","Ensure matched writeUTF/readUTF encoding on both sides.","For externally sourced bytes, decode with java.nio.charset.StandardCharsets.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 3-byte sequence had an invalid continuation byte\n    throw new IOException(\"Invalid modified-UTF-8 continuation: \" + e.getMessage(), e);\n}","preventionTips":["Inspect raw bytes at the reported offset to diagnose corruption.","Ensure writer/reader use the same modified-UTF-8 encoding.","Decode external standard-UTF-8 bytes with new String(bytes, StandardCharsets.UTF_8)."],"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"}