{"record":{"id":"a398823c22051a42","repo":"alibaba/canal","slug":"query-event-length-is-too-short","errorCode":null,"errorMessage":"Query event length is too short.","messagePattern":"Query event length is too short\\.","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"dbsync/src/main/java/com/taobao/tddl/dbsync/binlog/event/QueryLogEvent.java","lineNumber":413,"sourceCode":"                         boolean compatiablePercona) throws IOException{\n        this(header, buffer, descriptionEvent, compatiablePercona, false);\n    }\n\n    public QueryLogEvent(LogHeader header, LogBuffer buffer, FormatDescriptionLogEvent descriptionEvent,\n                         boolean compatiablePercona,\n                         boolean compress) throws IOException{\n        super(header);\n        this.compatiablePercona = compatiablePercona;\n        final int commonHeaderLen = descriptionEvent.commonHeaderLen;\n        final int postHeaderLen = descriptionEvent.postHeaderLen[header.type - 1];\n        /*\n         * We test if the event's length is sensible, and if so we compute\n         * data_len. We cannot rely on QUERY_HEADER_LEN here as it would not be\n         * format-tolerant. We use QUERY_HEADER_MINIMAL_LEN which is the same\n         * for 3.23, 4.0 & 5.0.\n         */\n        if (buffer.limit() < (commonHeaderLen + postHeaderLen)) {\n            throw new IOException(\"Query event length is too short.\");\n        }\n        int dataLen = buffer.limit() - (commonHeaderLen + postHeaderLen);\n        buffer.position(commonHeaderLen + Q_THREAD_ID_OFFSET);\n\n        sessionId = buffer.getUint32(); // Q_THREAD_ID_OFFSET\n        execTime = buffer.getUint32(); // Q_EXEC_TIME_OFFSET\n\n        // TODO: add a check of all *_len vars\n        final int dbLen = buffer.getUint8(); // Q_DB_LEN_OFFSET\n        errorCode = buffer.getUint16(); // Q_ERR_CODE_OFFSET\n\n        /*\n         * 5.0 format starts here. Depending on the format, we may or not have\n         * affected/warnings etc The remaining post-header to be parsed has\n         * length:\n         */\n        int statusVarsLen = 0;\n        if (postHeaderLen > QUERY_HEADER_MINIMAL_LEN) {","sourceCodeStart":395,"sourceCodeEnd":431,"githubUrl":"https://github.com/alibaba/canal/blob/87be50e87686a3e8af08c368d0e1ffd1f59eb04a/dbsync/src/main/java/com/taobao/tddl/dbsync/binlog/event/QueryLogEvent.java#L395-L431","documentation":"Thrown during construction of a QueryLogEvent when the buffer's total length (limit) is less than the sum of the common header length and post-header length. This means the event is too short to even contain its own header fields, indicating severe truncation or corruption.","triggerScenarios":"Constructing QueryLogEvent from a binlog buffer. The commonHeaderLen and postHeaderLen come from the FormatDescriptionLogEvent. If buffer.limit() < commonHeaderLen + postHeaderLen, the event cannot be parsed and the exception fires.","commonSituations":"Truncated binlog event from a network interruption during replication, a corrupt binlog file, mismatched FormatDescriptionLogEvent (wrong postHeaderLen table), or the buffer was sliced incorrectly so limit is too small.","solutions":["Verify the FormatDescriptionLogEvent used for parsing has the correct postHeaderLen values for the server's binlog format version.","Check buffer.limit() against the event's declared event-len to detect truncation.","Ensure network reliability between replicator and MySQL server (timeouts, reconnect handling).","Re-synchronize from a known-good binlog position if the event is genuinely truncated."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Pre-validate buffer size against expected header size\nint commonHeaderLen = descriptionEvent.commonHeaderLen;\nint postHeaderLen = descriptionEvent.postHeaderLen[header.type - 1];\nif (buffer.limit() < commonHeaderLen + postHeaderLen) {\n    logger.warn(\"Query event too short: limit={} < header={}\", buffer.limit(), commonHeaderLen + postHeaderLen);\n    return; // or throw domain exception\n}","typeGuard":null,"tryCatchPattern":"try {\n    QueryLogEvent event = new QueryLogEvent(header, buffer, descriptionEvent, compatiablePercona, compress);\n} catch (IOException e) {\n    if (e.getMessage().contains(\"too short\")) {\n        logger.warn(\"Truncated QueryLogEvent in binlog, skipping\");\n    }\n    throw e;\n}","preventionTips":["Verify the FormatDescriptionLogEvent's postHeaderLen table matches the MySQL server's binlog format.","Monitor replication network health for partial event reads.","Check buffer.limit() against the event header's event-len field before parsing."],"tags":["binlog","mysql","query-event","truncation","header-validation"],"backgroundTag":null,"analyzedSha":"87be50e87686a3e8af08c368d0e1ffd1f59eb04a","analyzedAt":"2026-08-14T04:30:11.918Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}