{"record":{"id":"bdd172691c107969","repo":"kopia/kopia","slug":"decompression-error","errorCode":null,"errorMessage":"decompression error","messagePattern":"decompression error","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"repo/compression/compressor_deflate.go","lineNumber":74,"sourceCode":"\n\tif err := w.Close(); err != nil {\n\t\treturn errors.Wrap(err, \"compression close error\")\n\t}\n\n\treturn nil\n}\n\nfunc (c *deflateCompressor) Decompress(output io.Writer, input io.Reader, withHeader bool) error {\n\tif withHeader {\n\t\tif err := verifyCompressionHeader(input, c.header); err != nil {\n\t\t\treturn err\n\t\t}\n\t}\n\n\tr := flate.NewReader(input)\n\n\tif err := iocopy.JustCopy(output, r); err != nil {\n\t\treturn errors.Wrap(err, \"decompression error\")\n\t}\n\n\treturn nil\n}\n","sourceCodeStart":56,"sourceCodeEnd":79,"githubUrl":"https://github.com/kopia/kopia/blob/82495e54b584c1ef6073c9e1be048f57f8aef078/repo/compression/compressor_deflate.go#L56-L79","documentation":"deflateCompressor.Decompress wraps a failure from iocopy.JustCopy while copying decompressed bytes from the flate.Reader to the output. The deflate stream was invalid (corrupt data, bad checksum/trailer) or the output write failed. Corrupt input is the most common cause: flate reports unexpected EOF or corrupt data before flagging it as io errors.","triggerScenarios":"Calling Decompress on bytes that are not valid deflate: truncated stream, bit-rotted blob, data compressed with raw deflate vs zlib confusion, or output writer errors mid-copy.","commonSituations":"Partial uploads stored as complete objects; files edited/truncated after compression; reading with the wrong wrap (raw flate vs gzip) so the decoder chokes on header bytes; full disk while writing large output.","solutions":["Verify the blob's stored checksum; re-upload/re-fetch if it does not match — corrupt source is the usual cause.","Run an independent flate/gzip integrity test (gzip -t / python zlib) on the raw bytes to confirm corruption.","Confirm you use the matching wrapper: library's flate reader expects plain deflate stream, not gzip-wrapped data.","Check the output writer (disk space, connection) if the unwrapped error is a write error rather than a decode error."],"exampleFix":"// before\nerr := comp.Decompress(out, bytes.NewReader(blob))\n// after\nif err := verifyChecksum(blob, expected); err != nil {\n    return refetchBlob(ctx, id) // corrupt source\n}\nerr := comp.Decompress(out, bytes.NewReader(blob))","handlingStrategy":"validation","validationCode":"if len(blob) < 4 { return errors.New(\"blob too short\") }\nif sum := sha256.Sum256(blob); !bytes.Equal(sum[:], storedChecksum) {\n    return errors.New(\"blob corrupt: checksum mismatch\")\n}\nerr := comp.Decompress(out, bytes.NewReader(blob), true)","typeGuard":null,"tryCatchPattern":"if err := comp.Decompress(out, r, true); err != nil {\n    if strings.Contains(err.Error(), \"decompression error\") {\n        return fmt.Errorf(\"deflate stream corrupt or output failed: %w\", err)\n    }\n    return err\n}","preventionTips":["Checksum every compressed blob at write time and verify before reading.","Ensure readers use the matching compressor (flate vs gzip wrap).","Keep output sinks healthy (disk space) for large decompressions."],"tags":["compression","corrupt-data","deflate"],"backgroundTag":"checksum-mismatch","analyzedSha":"82495e54b584c1ef6073c9e1be048f57f8aef078","analyzedAt":"2026-09-07T20:35:21.689Z","contentChangedAt":"2026-09-07T20:35:21.689Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}