{"record":{"id":"ae6a1a351f721438","repo":"prestodb/presto","slug":"zstd-jni-decompressor-failed-with","errorCode":null,"errorMessage":"Zstd JNI decompressor failed with ","messagePattern":"Zstd JNI decompressor failed with ","errorType":"exception","errorClass":"MalformedInputException","httpStatus":null,"severity":"error","filePath":"presto-orc/src/main/java/com/facebook/presto/orc/zstd/ZstdJniDecompressor.java","lineNumber":35,"sourceCode":"import io.airlift.compress.Decompressor;\nimport io.airlift.compress.MalformedInputException;\n\nimport java.nio.Buffer;\nimport java.nio.ByteBuffer;\n\nimport static java.lang.StrictMath.toIntExact;\n\npublic class ZstdJniDecompressor\n        implements Decompressor\n{\n    @Override\n    public int decompress(byte[] input, int inputOffset, int inputLength, byte[] output, int outputOffset, int maxOutputLength)\n            throws MalformedInputException\n    {\n        long size = Zstd.decompressByteArray(output, 0, maxOutputLength, input, inputOffset, inputLength);\n        if (Zstd.isError(size)) {\n            String errorName = Zstd.getErrorName(size);\n            throw new MalformedInputException(inputOffset, \"Zstd JNI decompressor failed with \" + errorName);\n        }\n        return toIntExact(size);\n    }\n\n    @Override\n    public void decompress(ByteBuffer input, ByteBuffer output)\n            throws MalformedInputException\n    {\n        if (input.isDirect() || output.isDirect() || !input.hasArray() || !output.hasArray()) {\n            throw new IllegalArgumentException(\"Non-direct byte buffer backed by byte array required\");\n        }\n        int inputOffset = input.arrayOffset() + input.position();\n        int outputOffset = output.arrayOffset() + output.position();\n\n        int written = decompress(input.array(), inputOffset, input.remaining(), output.array(), outputOffset, output.remaining());\n        ((Buffer) output).position(output.position() + written);\n    }\n}","sourceCodeStart":17,"sourceCodeEnd":53,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-orc/src/main/java/com/facebook/presto/orc/zstd/ZstdJniDecompressor.java#L17-L53","documentation":"ZstdJniDecompressor delegates to the Zstd JNI library; if Zstd reports an error code for the input bytes, a MalformedInputException is thrown embedding the JNI error name. The compressed block data did not decode as valid Zstandard.","triggerScenarios":"decompress called on bytes that are not valid Zstd (corruption, wrong block offset, or codec mismatch — e.g., file compressed with snappy but read as zstd).","commonSituations":"ORC file compression kind misread/mismatched; corrupted block boundaries; truncated zstd frame; incompatible zstd-jni version vs. writer's dictionary/frame features.","solutions":["Verify the ORC file's compression kind metadata matches ZSTD.","Scan the file with orc-tools to find the corrupt block.","Update the zstd-jni native library to a compatible version.","Re-transfer/repair the corrupted file."],"exampleFix":"// before\ncompressor = new ZstdJniDecompressor();\n// after: confirm codec from file metadata first\nif (metadata.getCompressionKind() != CompressionKind.ZSTD) {\n    compressor = Decompressor.forKind(metadata.getCompressionKind());\n} else {\n    compressor = new ZstdJniDecompressor();\n}","handlingStrategy":"try-catch","validationCode":"if (metadata.getCompressionKind() != CompressionKind.ZSTD) {\n    throw new IOException(\"codec mismatch, not zstd: \" + metadata.getCompressionKind());\n}","typeGuard":null,"tryCatchPattern":"try { return zstdDecompressor.decompress(in, off, len, out, oOff, max); } catch (MalformedInputException e) {\n    throw new DataCorruptionException(\"zstd decode failed: \" + e.getMessage(), e);\n}","preventionTips":["Verify compression kind in footer matches reader's decompressor.","Keep zstd-jni version compatible with the writer's zstd version.","Detect truncated frames via block-length sanity checks.","Run integrity scans on ingested files."],"tags":["orc","zstd","compression","jni"],"backgroundTag":"decompression-input-malformed","analyzedSha":"55bb57d202de3b926896fa966c2c4a44c779634e","analyzedAt":"2026-09-04T12:50:26.162Z","contentChangedAt":"2026-09-04T12:50:26.162Z","schemaVersion":2},"datasetVersion":"2026-09-11T21:17:09.523Z"}