{"record":{"id":"8cbdcb8200537fdb","repo":"oracle/graal","slug":"malformed-input-around-byte-d","errorCode":null,"errorMessage":"malformed input around byte %d","messagePattern":"malformed input around byte (.+?)","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"compiler/src/jdk.graal.compiler.libgraal/src/jdk/graal/compiler/libgraal/truffle/BinaryInput.java","lineNumber":293,"sourceCode":"                case 3:\n                case 4:\n                case 5:\n                case 6:\n                case 7:\n                    /* 0xxxxxxx */\n                    byteCount++;\n                    tempEncodingCharBuffer[charCount++] = (char) c1;\n                    break;\n                case 12:\n                case 13:\n                    /* 110x xxxx 10xx xxxx */\n                    byteCount += 2;\n                    if (byteCount > len) {\n                        throw new IllegalArgumentException(\"Partial character at end\");\n                    }\n                    c2 = tempEncodingByteBuffer[byteCount - 1];\n                    if ((c2 & 0xC0) != 0x80) {\n                        throw new IllegalArgumentException(\"malformed input around byte \" + byteCount);\n                    }\n                    tempEncodingCharBuffer[charCount++] = (char) (((c1 & 0x1F) << 6) | (c2 & 0x3F));\n                    break;\n                case 14:\n                    /* 1110 xxxx 10xx xxxx 10xx xxxx */\n                    byteCount += 3;\n                    if (byteCount > len) {\n                        throw new IllegalArgumentException(\"malformed input: partial character at end\");\n                    }\n                    c2 = tempEncodingByteBuffer[byteCount - 2];\n                    c3 = tempEncodingByteBuffer[byteCount - 1];\n                    if (((c2 & 0xC0) != 0x80) || ((c3 & 0xC0) != 0x80)) {\n                        throw new IllegalArgumentException(\"malformed input around byte \" + (byteCount - 1));\n                    }\n                    tempEncodingCharBuffer[charCount++] = (char) (((c1 & 0x0F) << 12) | ((c2 & 0x3F) << 6) | (c3 & 0x3F));\n                    break;\n                default:\n                    /* 10xx xxxx, 1111 xxxx */","sourceCodeStart":275,"sourceCodeEnd":311,"githubUrl":"https://github.com/oracle/graal/blob/a66e9ccd1d7bf2552883939aa0788dfd0e294aab/compiler/src/jdk.graal.compiler.libgraal/src/jdk/graal/compiler/libgraal/truffle/BinaryInput.java#L275-L311","documentation":"While decoding a 2-byte UTF-8 sequence, BinaryInput checks that the continuation byte has the 10xxxxxx pattern ((c2 & 0xC0) == 0x80). A violation throws IllegalArgumentException('malformed input around byte N') with the 1-based position of the bad byte. This is strict decoder validation copied from DataInputStream-style modified UTF-8 handling.","triggerScenarios":"readUTF encountering a lead byte 110xxxxx followed by a byte that is not a continuation byte (e.g. ASCII byte or another lead byte) inside the string payload.","commonSituations":"Bytes were produced by a different encoder (standard UTF-8 with surrogate pairs vs modified UTF-8), memory corruption on the native side, or stream misalignment where readUTF starts at the wrong offset after a previous malformed record.","solutions":["Ensure the string was written by BinaryOutput.writeUTF (modified UTF-8, no plain 4-byte UTF-8 sequences).","Check stream alignment: verify the preceding reads consumed exactly the bytes they declared (tags, lengths).","Regenerate the marshalled data with matching producer/consumer versions.","Avoid hand-constructing the binary format; always use BinaryOutput/BinaryInput pairs."],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n    String s = in.readUTF();\n} catch (IllegalArgumentException e) {\n    if (e.getMessage() != null && e.getMessage().startsWith(\"malformed input around byte\")) {\n        // treat record as corrupt: reset stream position, skip or re-transfer\n    }\n}","preventionTips":["Never hand-encode the wire format; always pair BinaryOutput with BinaryInput","Check stream alignment after every tagged read","Round-trip test new payload types before deploying"],"tags":["libgraal","truffle","encoding","utf-8"],"backgroundTag":null,"analyzedSha":"a66e9ccd1d7bf2552883939aa0788dfd0e294aab","analyzedAt":"2026-08-14T13:58:47.161Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}