{"record":{"id":"cfb6225be6fc3919","repo":"alibaba/canal","slug":"uncompress-failed","errorCode":null,"errorMessage":"uncompress failed ","messagePattern":"uncompress failed ","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"dbsync/src/main/java/com/taobao/tddl/dbsync/binlog/LogBuffer.java","lineNumber":1764,"sourceCode":"     * \r\n     * @return\r\n     */\r\n    public LogBuffer uncompressBuf() {\r\n        int lenPad = getInt8();\r\n        long len = getUncompressLong(lenPad & 0x07);\r\n        int alg = (lenPad & 0x70) >> 4;\r\n        LogBuffer buffer = null;\r\n        try {\r\n            switch (alg) {\r\n                case 0:\r\n                    buffer = uncompressZlib(limit - position);\r\n                    break;\r\n                default:\r\n                    // bad algorithm\r\n                    return this;\r\n            }\r\n        } catch (Exception e) {\r\n            throw new IllegalArgumentException(\"uncompress failed \", e);\r\n        }\r\n\r\n        if (buffer.limit() != len) {\r\n            throw new IllegalArgumentException(\r\n                \"uncompress lenght not match, expected : \" + len + \" , but actual : \" + buffer.limit());\r\n        }\r\n        return buffer;\r\n    }\r\n\r\n    private LogBuffer uncompressZlib(int len) throws Exception {\r\n        if (position + len > limit || position < 0) {\r\n            throw new IllegalArgumentException(\"limit excceed: \" + (position + len));\r\n        }\r\n\r\n        try (DeflateCompressorInputStream in = new DeflateCompressorInputStream(\r\n            new ByteArrayInputStream(buffer, position, position + len))) {\r\n            byte[] decodeBytes = IOUtils.toByteArray(in);\r\n            return new LogBuffer(decodeBytes, 0, decodeBytes.length);\r","sourceCodeStart":1746,"sourceCodeEnd":1782,"githubUrl":"https://github.com/alibaba/canal/blob/87be50e87686a3e8af08c368d0e1ffd1f59eb04a/dbsync/src/main/java/com/taobao/tddl/dbsync/binlog/LogBuffer.java#L1746-L1782","documentation":"A catch-all wrapper thrown when any Exception occurs during zlib decompression of a MariaDB compressed binlog event. The original exception is chained as the cause. The actual failure is inside uncompressZlib(), which uses Apache Commons Compress's DeflateCompressorInputStream to inflate the data.","triggerScenarios":"LogBuffer.uncompressBuf() is called for a MariaDB compressed log event. The algorithm byte indicates zlib (alg=0), so uncompressZlib() is invoked. Any exception from the decompression (corrupt compressed stream, truncated data, invalid zlib header) is caught and re-thrown with this message.","commonSituations":"MariaDB binlog compression with a corrupt deflate stream, network-level data corruption during replication, partial event reads due to socket timeouts, or a version mismatch where the parser attempts to decompress data that is not actually compressed.","solutions":["Examine the chained cause exception (e.getCause()) for the specific decompression failure — e.g., ZipException, EOFException, or DataFormatException.","Verify the MariaDB server version and its binlog compression settings match what the parser expects.","Check network reliability between the replicator and the MariaDB server — use TCP keepalive and proper timeouts.","If the compressed payload is genuinely corrupt, skip the event and re-request from the last known-good binlog position."],"exampleFix":"// before\nLogBuffer decompressed = buffer.uncompressBuf();\n\n// after: inspect the cause for diagnostics\ntry {\n    LogBuffer decompressed = buffer.uncompressBuf();\n} catch (IllegalArgumentException e) {\n    Throwable root = e.getCause() != null ? e.getCause() : e;\n    logger.error(\"Binlog decompression failed at pos={}, root cause: {}\",\n        buffer.position(), root.getClass().getSimpleName(), root);\n    throw e;\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n    LogBuffer decompressed = buffer.uncompressBuf();\n} catch (IllegalArgumentException e) {\n    Throwable cause = e.getCause();\n    logger.error(\"Binlog decompression failed, root cause: {}\",\n        cause != null ? cause.getMessage() : \"unknown\", e);\n    // skip event or re-sync replication\n}","preventionTips":["Verify MariaDB server binlog compression configuration matches parser expectations.","Monitor replication network health — partial reads due to socket issues can corrupt compressed payloads.","Enable binlog checksum verification to detect corruption before decompression."],"tags":["compression","binlog","mariadb","zlib","deflate"],"backgroundTag":null,"analyzedSha":"87be50e87686a3e8af08c368d0e1ffd1f59eb04a","analyzedAt":"2026-08-14T04:30:11.918Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}