{"record":{"id":"1067d966d9b25f72","repo":"alibaba/canal","slug":"uncompress-lenght-not-match-expected-but-act","errorCode":null,"errorMessage":"uncompress lenght not match, expected :  , but actual : ","messagePattern":"uncompress lenght not match, expected :  , but actual : ","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"dbsync/src/main/java/com/taobao/tddl/dbsync/binlog/LogBuffer.java","lineNumber":1768,"sourceCode":"        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\n        }\r\n    }\r\n\r\n    /**\r","sourceCodeStart":1750,"sourceCodeEnd":1786,"githubUrl":"https://github.com/alibaba/canal/blob/87be50e87686a3e8af08c368d0e1ffd1f59eb04a/dbsync/src/main/java/com/taobao/tddl/dbsync/binlog/LogBuffer.java#L1750-L1786","documentation":"Thrown after successful zlib decompression when the decompressed data length does not match the expected uncompressed length (len, decoded from the event header). The expected length is derived from getUncompressLong(lenPad & 0x07). A mismatch means the compressed stream decompressed to a different size than the header declared, indicating corruption in either the header or the compressed payload.","triggerScenarios":"LogBuffer.uncompressBuf() successfully decompresses data via uncompressZlib(), but buffer.limit() (actual decompressed size) != len (expected size from the 3-bit length encoding in the event header). Note the typo 'lenght' in the message.","commonSituations":"Corrupt compressed event where the header's declared uncompressed size is wrong, a truncated compressed stream that Apache Commons Compress partially decoded, or a binlog produced by a MariaDB version with a different compression length encoding.","solutions":["Log both the expected (len) and actual (buffer.limit()) sizes to understand the discrepancy magnitude.","Check if the event is truncated — if actual < expected, the compressed payload was cut short.","Verify the lenPad byte parsing: len comes from getUncompressLong(lenPad & 0x07), which encodes the length type (1, 2, 3, or 4 byte length field).","Re-synchronize replication from a known-good binlog position."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// After decompression, the library checks buffer.limit() == len.\n// Callers can pre-validate by checking the expected uncompressed size from the event header.\n// This is done internally by uncompressBuf(); no external pre-check is available.","typeGuard":null,"tryCatchPattern":"try {\n    LogBuffer decompressed = buffer.uncompressBuf();\n} catch (IllegalArgumentException e) {\n    if (e.getMessage().contains(\"uncompress lenght not match\")) {\n        logger.warn(\"Decompressed size mismatch — corrupt compressed payload or wrong length header\");\n    }\n    throw e;\n}","preventionTips":["Verify the lenPad byte is correctly parsed — the uncompressed length encoding depends on lenPad & 0x07.","Check for binlog corruption if the mismatch is consistent across events.","Monitor MariaDB version changes that might alter the compression header format."],"tags":["compression","binlog","mariadb","zlib","length-mismatch"],"backgroundTag":null,"analyzedSha":"87be50e87686a3e8af08c368d0e1ffd1f59eb04a","analyzedAt":"2026-08-14T04:30:11.918Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}