{"record":{"id":"fb4d62cc7d1b0c72","repo":"GitoxideLabs/gitoxide","slug":"corrupt-deflate-stream-cause","errorCode":null,"errorMessage":"corrupt deflate stream: {cause}","messagePattern":"corrupt deflate stream: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"gix-zlib/src/stream/inflate.rs","lineNumber":43,"sourceCode":"            dst = &mut dst[written..];\n            consumed = (state.total_in() - before_in) as usize;\n        }\n        rd.consume(consumed);\n\n        match ret {\n            // The stream has officially ended, nothing more to do here.\n            Ok(Status::StreamEnd) => return Ok(total_written),\n            // Either input our output are depleted even though the stream is not depleted yet.\n            Ok(Status::Ok | Status::BufError) if eof || dst.is_empty() => return Ok(total_written),\n            // Some progress was made in both the input and the output, it must continue to reach the end.\n            Ok(Status::Ok | Status::BufError) if consumed != 0 || written != 0 => continue,\n            // A strange state, where zlib makes no progress but isn't done either. Call it out.\n            Ok(Status::Ok | Status::BufError) => unreachable!(\"Definitely a bug somewhere\"),\n            // Keep the underlying zlib error so callers can tell a checksum mismatch\n            // (`incorrect data check`) apart from genuine stream corruption.\n            Err(err) => {\n                let cause = state.error_message().map_or_else(|| err.to_string(), String::from);\n                return Err(io::Error::new(\n                    io::ErrorKind::InvalidInput,\n                    format!(\"corrupt deflate stream: {cause}\"),\n                ));\n            }\n        }\n    }\n}\n","sourceCodeStart":25,"sourceCodeEnd":51,"githubUrl":"https://github.com/GitoxideLabs/gitoxide/blob/e73179060badf27222d790981fac3f84c1830a7e/gix-zlib/src/stream/inflate.rs#L25-L51","documentation":"During inflation, the zlib decoder returned an error; the stream is corrupt. The underlying zlib error message is preserved in the message so callers can distinguish a checksum mismatch (`incorrect data check`) from genuine stream corruption. Returned as `InvalidInput` from `read()`.","triggerScenarios":"`gix_zlib::stream::inflate` `read()` encounters invalid deflate data, a truncated stream, or an Adler-32 checksum mismatch in the compressed input.","commonSituations":"Reading zlib-compressed data from a corrupted pack/loose object file; concatenating or truncating compressed blobs; feeding non-zlib data to an inflate stream.","solutions":["Verify the input source integrity (re-fetch or restore the corrupted object/pack)","Check that the complete compressed stream (including Adler-32 trailer) is being written to the inflater","Compare the zlib message: 'incorrect data check' implies data corruption after decompression, other messages point at malformed deflate data"],"exampleFix":"// before\nlet mut buf = read_partial_file(path)?; // truncated\ninflate.read_to_end(&mut out)?; // corrupt deflate stream\n// after\nlet buf = std::fs::read(path).expect(\"complete compressed input\");\nassert!(!buf.is_empty());\ninflate.read_to_end(&mut out)?;","handlingStrategy":"try-catch","validationCode":"// Rust: confirm input is a complete zlib stream (checks 2-byte header)\nfn looks_like_zlib(buf: &[u8]) -> bool {\n    buf.len() >= 2 && (buf[0] & 0x0f) == 8 && ((buf[0] as u16) << 8 | buf[1] as u16) % 31 == 0\n}","typeGuard":null,"tryCatchPattern":"match inflate_stream.read_to_end(&mut out) {\n    Err(e) if e.kind() == std::io::ErrorKind::InvalidInput\n        && e.to_string().contains(\"corrupt deflate stream\") => {\n        if e.to_string().contains(\"incorrect data check\") {\n            eprintln!(\"checksum mismatch: object data is corrupted; re-fetch\");\n        } else {\n            eprintln!(\"malformed deflate data: {e}\");\n        }\n    }\n    other => other?,\n}","preventionTips":["Verify pack/object integrity with `git fsck` or gix fsck equivalents","Write the entire compressed payload (including trailer) to the inflater before finishing","Detect truncated writes upstream; do not feed partial buffers as complete streams"],"tags":["zlib","compression","data-corruption","io"],"backgroundTag":"checksum-mismatch","analyzedSha":"e73179060badf27222d790981fac3f84c1830a7e","analyzedAt":"2026-09-08T11:26:50.865Z","contentChangedAt":"2026-09-08T11:26:50.865Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}