{"record":{"id":"0a861b485b272912","repo":"grpc/grpc-java","slug":"not-in-gzip-format","errorCode":null,"errorMessage":"Not in GZIP format","messagePattern":"Not in GZIP format","errorType":"exception","errorClass":"ZipException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/io/grpc/internal/GzipInflatingBuffer.java","lineNumber":323,"sourceCode":"          break;\n        default:\n          throw new AssertionError(\"Invalid state: \" + state);\n      }\n    }\n    // If we finished a gzip block, check if we have enough bytes to read another header\n    isStalled =\n        !madeProgress\n            || (state == State.HEADER && gzipMetadataReader.readableBytes() < GZIP_HEADER_MIN_SIZE);\n\n    return bytesRead;\n  }\n\n  private boolean processHeader() throws ZipException {\n    if (gzipMetadataReader.readableBytes() < GZIP_HEADER_MIN_SIZE) {\n      return false;\n    }\n    if (gzipMetadataReader.readUnsignedShort() != GZIP_MAGIC) {\n      throw new ZipException(\"Not in GZIP format\");\n    }\n    if (gzipMetadataReader.readUnsignedByte() != 8) {\n      throw new ZipException(\"Unsupported compression method\");\n    }\n    gzipHeaderFlag = gzipMetadataReader.readUnsignedByte();\n    gzipMetadataReader.skipBytes(6 /* remaining header bytes */);\n    state = State.HEADER_EXTRA_LEN;\n    return true;\n  }\n\n  private boolean processHeaderExtraLen() {\n    if ((gzipHeaderFlag & HEADER_EXTRA_FLAG) != HEADER_EXTRA_FLAG) {\n      state = State.HEADER_NAME;\n      return true;\n    }\n    if (gzipMetadataReader.readableBytes() < UNSIGNED_SHORT_SIZE) {\n      return false;\n    }","sourceCodeStart":305,"sourceCodeEnd":341,"githubUrl":"https://github.com/grpc/grpc-java/blob/64daddc1f3d1975670f769f3e97bde8b2ba32d25/core/src/main/java/io/grpc/internal/GzipInflatingBuffer.java#L305-L341","documentation":"GzipInflatingBuffer decompresses gZIP-framed data and must first read the GZIP header, which starts with the magic bytes 0x1f8b. If the stream's first two bytes do not match GZIP_MAGIC, it throws java.util.zip.ZipException(\"Not in GZIP format\"), meaning the payload is not gzip-compressed data despite being announced as such.","triggerScenarios":"A message declared with the 'gzip' gRPC encoding is actually plain (identity) bytes, truncated, or double-wrapped in another container, so inflateBytes/processHeader reads a non-0x1f8b magic number at the start of the stream.","commonSituations":"Server/client encoding negotiation mismatch (content-coding says gzip but data is raw); corrupt or truncated response bodies; misconfigured compression interceptors or proxies; double-decompression where an outer layer already inflated the data.","solutions":["Verify both peers agree on the compression encoding (grpc-encoding: gzip) and only send gzip when negotiated; otherwise send identity.","Check for truncation/corruption (proxy buffering, content-length mismatch) that chops the gzip header bytes.","Remove double-compression: if an interceptor already gzips payloads, don't also enable transport gzip.","Catch ZipException on the decompression path and fall back to identity decoding when the magic bytes are missing."],"exampleFix":"// before\nbyte[] payload = plainBytes; // advertised as gzip\n// after\nbyte[] payload = gzip(plainBytes); // actually compress before sending with grpc-encoding: gzip","handlingStrategy":"try-catch","validationCode":"if (data.length < 2 || (data[0] & 0xff) != 0x1f || (data[1] & 0xff) != 0x8b) {\n  throw new IllegalArgumentException(\"payload is not gzip; grpc-encoding mismatch?\");\n}","typeGuard":"boolean isGzip(byte[] b) { return b != null && b.length >= 2 && b[0] == 0x1f && b[1] == (byte) 0x8b; }","tryCatchPattern":"try {\n  msg = gzipDecompressor.decompress(frame);\n} catch (ZipException e) {\n  // treat as identity or fail the call with INTERNAL status\n}","preventionTips":["Ensure gzip encoding is only negotiated when both peers support it.","Check content-length and proxy configs for truncation.","Avoid double-compression between interceptors and transport."],"tags":["grpc","gzip","compression","corrupt-data"],"backgroundTag":"checksum-mismatch","analyzedSha":"64daddc1f3d1975670f769f3e97bde8b2ba32d25","analyzedAt":"2026-09-08T06:14:57.704Z","contentChangedAt":"2026-09-08T06:14:57.704Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}