{"record":{"id":"3cd9f0e0db8eaf14","repo":"apache/incubator-seata","slug":"gzip-decompress-error","errorCode":null,"errorMessage":"gzip decompress error","messagePattern":"gzip decompress error","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"compressor/seata-compressor-gzip/src/main/java/org/apache/seata/compressor/gzip/GzipUtil.java","lineNumber":60,"sourceCode":"            throw new RuntimeException(\"gzip compress error\", e);\n        }\n    }\n\n    public static byte[] decompress(byte[] bytes) {\n        if (bytes == null) {\n            throw new NullPointerException(\"bytes is null\");\n        }\n\n        ByteArrayOutputStream out = new ByteArrayOutputStream();\n        try (GZIPInputStream gunzip = new GZIPInputStream(new ByteArrayInputStream(bytes))) {\n            byte[] buffer = new byte[BUFFER_SIZE];\n            int n;\n            while ((n = gunzip.read(buffer)) > -1) {\n                out.write(buffer, 0, n);\n            }\n            return out.toByteArray();\n        } catch (IOException e) {\n            throw new RuntimeException(\"gzip decompress error\", e);\n        }\n    }\n}\n","sourceCodeStart":42,"sourceCodeEnd":64,"githubUrl":"https://github.com/apache/incubator-seata/blob/e01f97c6db397165050caa6764020410c2c8199a/compressor/seata-compressor-gzip/src/main/java/org/apache/seata/compressor/gzip/GzipUtil.java#L42-L64","documentation":"Wrapped IOException thrown by GzipUtil.decompress as RuntimeException(\"gzip decompress error\", e). It fires when GZIPInputStream cannot read the payload: the data is not in gzip format (bad magic bytes), the stream is truncated/corrupted, or the CRC/checksum fails on finish. The original IOException is attached as the cause for diagnosis.","triggerScenarios":"Passing bytes that were not gzip-compressed (raw, zip, or lz4 payloads); a truncated byte array (partial network read, wrong length prefix); corrupted rollback-info stored in a database table; calling decompress on an empty non-null array (new byte[0]) which makes the GZIPInputStream constructor throw ZipException 'Not in GZIP format'.","commonSituations":"Compressor type mismatch between seata client and server (client compresses with zstd, server decompresses with gzip); corrupted undo_log/branch session data after a DB character-set incident; a proxy or middleware mangling binary bodies; version upgrade changing the default compressor.","solutions":["Inspect the cause in the stack trace — 'Not in GZIP format' means wrong data, 'Unexpected end of ZLIB input stream' means truncation.","Verify the compressor id/type configured on both ends of the RPC matches (registry and compressor config).","If data comes from storage, re-read or regenerate it (e.g. clear the poisoned undo_log rows) rather than retrying decompression.","Sanity-check the first two bytes are 0x1f 0x8b before calling decompress."],"exampleFix":"// before\nbyte[] out = GzipUtil.decompress(bytes);\n\n// after\nif (bytes.length < 2 || (bytes[0] & 0xff) != 0x1f || (bytes[1] & 0xff) != 0x8b) {\n    throw new IllegalArgumentException(\"payload is not gzip (bad magic bytes)\");\n}\nbyte[] out = GzipUtil.decompress(bytes);","handlingStrategy":"try-catch","validationCode":"boolean isGzip(byte[] b) {\n    return b != null && b.length >= 2 && (b[0] & 0xff) == 0x1f && (b[1] & 0xff) == 0x8b;\n}","typeGuard":null,"tryCatchPattern":"try {\n    byte[] out = GzipUtil.decompress(bytes);\n} catch (RuntimeException e) {\n    if (e.getMessage() != null && e.getMessage().contains(\"gzip decompress error\")) {\n        // treat as corrupt/foreign payload: log cause, reject message, do not retry\n    } else { throw e; }\n}","preventionTips":["Keep compressor type identical on client and server","Check gzip magic bytes (0x1f 0x8b) before decompressing data of uncertain origin","Never store compressed bytes in text-typed DB columns or through charset-recoding layers"],"tags":["gzip","compression","corrupt-data","io","seata"],"backgroundTag":null,"analyzedSha":"e01f97c6db397165050caa6764020410c2c8199a","analyzedAt":"2026-08-14T10:23:53.097Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}