{"record":{"id":"5153c85b931c7a7a","repo":"apache/druid","slug":"unable-to-decompress-zstd-data-s","errorCode":null,"errorMessage":"Unable to decompress zstd data: %s","messagePattern":"Unable to decompress zstd data: (.+?)","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"processing/src/main/java/org/apache/druid/segment/data/CompressionStrategy.java","lineNumber":458,"sourceCode":"            in.position(),\n            numBytes\n        );\n        out.limit(out.position() + decompressedBytes);\n      }\n    }\n\n    private static void decompressHeap(byte[] inputBytes, int numBytes, byte[] outputBytes, ByteBuffer out)\n    {\n      final long decompressedBytes = Zstd.decompressByteArray(\n          outputBytes,\n          0,\n          outputBytes.length,\n          inputBytes,\n          0,\n          numBytes\n      );\n      if (Zstd.isError(decompressedBytes)) {\n        throw new RuntimeException(\"Unable to decompress zstd data: \" + Zstd.getErrorName(decompressedBytes));\n      }\n      out.put(outputBytes, 0, (int) decompressedBytes);\n      out.flip();\n    }\n  }\n\n  /**\n   * Logs info relating to whether LZ4 is using native or pure Java implementations\n   */\n  private static void logLZ4State()\n  {\n    LOG.debug(\"java.library.path: \" + System.getProperty(\"java.library.path\"));\n    LZ4Factory fastestInstance = LZ4Factory.fastestInstance();\n    try {\n      //noinspection ObjectEquality\n      if (fastestInstance == LZ4Factory.nativeInstance()) {\n        LOG.debug(\"LZ4 compression is using native instance.\");\n      }","sourceCodeStart":440,"sourceCodeEnd":476,"githubUrl":"https://github.com/apache/druid/blob/9b90983fd291f26935af934383ce360473179e4d/processing/src/main/java/org/apache/druid/segment/data/CompressionStrategy.java#L440-L476","documentation":"The Zstd Decompressor's decompressHeap calls Zstd.decompress into a preallocated output array and checks Zstd.isError on the result. When the native zstd call returns an error (bad magic bytes, truncated input, wrong frame), a RuntimeException is thrown naming the zstd error code. It indicates the compressed bytes are not valid zstd data.","triggerScenarios":"Decompressing a byte array that is truncated, corrupted, or was never zstd-compressed (e.g. wrong strategy used at write time).","commonSituations":"Segments written with a different compression strategy than the reader assumes; disk corruption or incomplete segment transfer; mixing zstd-compressed blocks with uncompressed ones.","solutions":["Verify the segment's compression strategy metadata matches the data (re-ingest if the spec changed strategy mid-write)","Check segment file integrity/transfer completeness; re-copy or re-download the segment","Re-generate the corrupt segment from source data"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"if (input.length < 4 || !looksLikeZstdFrame(input)) { throw new IllegalArgumentException(\"not zstd data\"); }","typeGuard":null,"tryCatchPattern":"try {\n  strategy.decompress(source, input, output);\n} catch (RuntimeException e) {\n  if (e.getMessage().startsWith(\"Unable to decompress zstd\")) {\n    // re-fetch or re-ingest the corrupt segment\n  } else throw e;\n}","preventionTips":["Verify compression strategy metadata matches how blocks were written","Checksum segments after transfer and before read","Never mix compression strategies within a segment"],"tags":["java","compression","zstd","corruption"],"backgroundTag":"checksum-mismatch","analyzedSha":"9b90983fd291f26935af934383ce360473179e4d","analyzedAt":"2026-09-07T13:32:30.957Z","contentChangedAt":"2026-09-07T13:32:30.957Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}