{"record":{"id":"35befa1e42b3d249","repo":"apache/pulsar","slug":"wraps-dataformatexception-from-zlib-inflate","errorCode":null,"errorMessage":"(wraps DataFormatException from zlib inflate)","messagePattern":"\\(wraps DataFormatException from zlib inflate\\)","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"pulsar-common/src/main/java/org/apache/pulsar/common/compression/CompressionCodecZLib.java","lineNumber":122,"sourceCode":"        int offset;\n        if (encoded.hasArray()) {\n            array = encoded.array();\n            offset = encoded.arrayOffset() + encoded.readerIndex();\n        } else {\n            array = new byte[len];\n            encoded.getBytes(encoded.readerIndex(), array);\n            offset = 0;\n        }\n\n        int resultLength;\n        Inflater inflater = this.inflater.get();\n        inflater.reset();\n        inflater.setInput(array, offset, len);\n\n        try {\n            resultLength = inflater.inflate(uncompressed.array(), uncompressed.arrayOffset(), uncompressedLength);\n        } catch (DataFormatException e) {\n            throw new IOException(e);\n        }\n\n        checkArgument(resultLength == uncompressedLength);\n\n        uncompressed.writerIndex(uncompressedLength);\n        return uncompressed;\n    }\n}\n","sourceCodeStart":104,"sourceCodeEnd":131,"githubUrl":"https://github.com/apache/pulsar/blob/820761864ed8e2a7d2e52dd9763ad2ae117c1395/pulsar-common/src/main/java/org/apache/pulsar/common/compression/CompressionCodecZLib.java#L104-L131","documentation":"CompressionCodecZLib.decode inflates a compressed payload with java.util.zip.Inflater. If the bytes are not valid zlib data (corrupt, truncated, or produced with a different algorithm), inflate() throws DataFormatException, which is wrapped in an IOException and rethrown.","triggerScenarios":"decode() called on a buffer whose zlib header/checksum is corrupt, a payload truncated mid-stream, or a message that was compressed with a codec other than ZLib but decoded as ZLib.","commonSituations":"Bookkeeper/ledger corruption, manual topic data edits, reading messages written by a producer with mismatched compression settings, network/disk truncation during replication.","solutions":["Verify the message was actually produced with ZLIB compression and use the matching codec to decode","Check disk/storage health for corruption of the underlying ledger data","Reproduce the data from a healthy source or skip the corrupted entries"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"if (compressed == null || compressed.readableBytes() < 2) {\n    throw new IllegalArgumentException(\"payload too small to be zlib data\");\n}\nint cmf = compressed.getByte(0) & 0xff;\nif ((cmf & 0x0f) != 8) {\n    throw new IllegalArgumentException(\"not a zlib (deflate) payload\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    return codec.decode(compressed);\n} catch (IOException e) {\n    throw new IllegalStateException(\"Corrupt zlib payload\", e);\n}","preventionTips":["Always decode with the same codec used at produce time (read compression field from the message metadata)","Monitor ledger/bookkeeper storage health to catch corruption early","Never truncate compressed buffers before writing to storage"],"tags":["compression","zlib","io","data-corruption"],"backgroundTag":"decompression-failed-corrupt-payload","analyzedSha":"820761864ed8e2a7d2e52dd9763ad2ae117c1395","analyzedAt":"2026-09-06T00:14:20.138Z","contentChangedAt":"2026-09-06T00:14:20.138Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}