{"record":{"id":"5cf7b04aab52920f","repo":"databendlabs/databend","slug":"zip-type-requires-additional-judgment-and-use-dec","errorCode":null,"errorMessage":"Zip type requires additional judgment and use `decompress_all_zip`","messagePattern":"Zip type requires additional judgment and use `decompress_all_zip`","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/common/compress/src/decode.rs","lineNumber":80,"sourceCode":"    /// Decoder for [`CompressAlgorithm::Zlib`]\n    Zlib(ZlibDecoder),\n    /// Decoder for [`CompressAlgorithm::Zstd`]\n    Zstd(ZstdDecoder),\n}\n\nimpl From<CompressAlgorithm> for DecompressCodec {\n    fn from(v: CompressAlgorithm) -> Self {\n        match v {\n            CompressAlgorithm::Brotli => DecompressCodec::Brotli(Box::new(BrotliDecoder::new())),\n            CompressAlgorithm::Bz2 => DecompressCodec::Bz2(BzDecoder::new()),\n            CompressAlgorithm::Deflate => DecompressCodec::Deflate(DeflateDecoder::new()),\n            CompressAlgorithm::Gzip => DecompressCodec::Gzip(GzipDecoder::new()),\n            CompressAlgorithm::Lzma => DecompressCodec::Lzma(LzmaDecoder::new()),\n            CompressAlgorithm::Xz => DecompressCodec::Xz(XzDecoder::new()),\n            CompressAlgorithm::Zlib => DecompressCodec::Zlib(ZlibDecoder::new()),\n            CompressAlgorithm::Zstd => DecompressCodec::Zstd(ZstdDecoder::new()),\n            CompressAlgorithm::Zip => {\n                unreachable!(\"Zip type requires additional judgment and use `decompress_all_zip`\")\n            }\n        }\n    }\n}\n\nimpl Decode for DecompressCodec {\n    fn reinit(&mut self) -> Result<()> {\n        match self {\n            DecompressCodec::Brotli(v) => v.reinit(),\n            DecompressCodec::Bz2(v) => v.reinit(),\n            DecompressCodec::Deflate(v) => v.reinit(),\n            DecompressCodec::Gzip(v) => v.reinit(),\n            DecompressCodec::Lzma(v) => v.reinit(),\n            DecompressCodec::Xz(v) => v.reinit(),\n            DecompressCodec::Zlib(v) => v.reinit(),\n            DecompressCodec::Zstd(v) => v.reinit(),\n        }\n    }","sourceCodeStart":62,"sourceCodeEnd":98,"githubUrl":"https://github.com/databendlabs/databend/blob/288d84d76e20a2f8f7173bda9691eb6ece301aa9/src/common/compress/src/decode.rs#L62-L98","documentation":"The decompression codec factory in src/common/compress cannot build a generic streaming decoder for the Zip algorithm: ZIP archives hold multiple named entries and require per-entry handling, so CompressAlgorithm::Zip hits an unreachable!() panic in DecompressCodec::from. The message directs callers to use decompress_all_zip instead, which iterates and decompresses every entry of the archive.","triggerScenarios":"Constructing a DecompressCodec via From/`from` with CompressAlgorithm::Zip — e.g. a compression algorithm resolved from configuration or file metadata equals Zip and the generic decode path is taken instead of the dedicated zip path.","commonSituations":"A user configures compression = zip for a stage/stream decoder that only supports single-stream codecs; auto-detection of a .zip upload routes it to the generic decompressor; refactoring code that previously special-cased Zip removed the guard before calling from().","solutions":["Route Zip inputs to decompress_all_zip before constructing a DecompressCodec","Check the CompressAlgorithm before calling from() and only build a codec for Gzip/Lzma/Xz/Zlib/Zstd","Change configuration to a supported streaming algorithm (e.g. gzip, zstd) when per-entry zip semantics are not needed","Replace the panic with a typed UnsupportedAlgorithm error for clearer diagnostics"],"exampleFix":"// before\nlet codec = DecompressCodec::from(algorithm); // panics when algorithm == Zip\n// after\nlet data = match algorithm {\n    CompressAlgorithm::Zip => decompress_all_zip(&raw)?,\n    alg => DecompressCodec::from(alg).decode(&raw)?,\n};","handlingStrategy":"validation","validationCode":"if algorithm == CompressAlgorithm::Zip {\n    return decompress_all_zip(&input).map_err(|e| e.into());\n}","typeGuard":"fn is_streaming_codec(alg: CompressAlgorithm) -> bool {\n    !matches!(alg, CompressAlgorithm::Zip)\n}","tryCatchPattern":"match DecompressCodec::try_from(algorithm) {\n    Ok(codec) => codec.decode(&data)?,\n    Err(UnsupportedAlgorithm(Zip)) => decompress_all_zip(&data)?,\n}","preventionTips":["Never pass CompressAlgorithm::Zip into the generic codec factory","Detect .zip inputs (magic bytes PK\\x03\\x04) and route to decompress_all_zip early","Document that single-stream codecs exclude Zip in configuration validation"],"tags":["compression","zip","panic","unsupported-algorithm"],"backgroundTag":"unsupported-operation","analyzedSha":"288d84d76e20a2f8f7173bda9691eb6ece301aa9","analyzedAt":"2026-09-11T11:29:36.208Z","contentChangedAt":"2026-09-11T11:29:36.208Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}