{"record":{"id":"90015926dee32d7f","repo":"hyperledger/fabric","slug":"error-creating-gzip-reader","errorCode":null,"errorMessage":"error creating gzip reader","messagePattern":"error creating gzip reader","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/ledger/kvledger/txmgmt/statedb/statecouchdb/couchdb.go","lineNumber":797,"sourceCode":"\t\t}\n\n\t\t// Create an attachment structure and load it.\n\t\tattachment := &attachmentInfo{}\n\t\tattachment.ContentType = p.Header.Get(\"Content-Type\")\n\t\tcontentDispositionParts := strings.Split(p.Header.Get(\"Content-Disposition\"), \";\")\n\n\t\tif strings.TrimSpace(contentDispositionParts[0]) != \"attachment\" {\n\t\t\tcontinue\n\t\t}\n\n\t\tswitch p.Header.Get(\"Content-Encoding\") {\n\t\tcase \"gzip\": // See if the part is gzip encoded\n\n\t\t\tvar respBody []byte\n\n\t\t\tgr, err := gzip.NewReader(p)\n\t\t\tif err != nil {\n\t\t\t\treturn nil, \"\", errors.Wrap(err, \"error creating gzip reader\")\n\t\t\t}\n\t\t\trespBody, err = io.ReadAll(gr)\n\t\t\tif err != nil {\n\t\t\t\treturn nil, \"\", errors.Wrap(err, \"error reading gzip data\")\n\t\t\t}\n\n\t\t\tcouchdbLogger.Debugf(\"[%s] Retrieved attachment data\", dbclient.dbName)\n\t\t\tattachment.AttachmentBytes = respBody\n\t\t\tattachment.Length = uint64(len(attachment.AttachmentBytes))\n\t\t\tattachment.Name = p.FileName()\n\t\t\tattachments = append(attachments, attachment)\n\n\t\tdefault:\n\n\t\t\t// retrieve the data,  this is not gzip\n\t\t\tpartdata, err := io.ReadAll(p)\n\t\t\tif err != nil {\n\t\t\t\treturn nil, \"\", errors.Wrap(err, \"error reading multipart data\")","sourceCodeStart":779,"sourceCodeEnd":815,"githubUrl":"https://github.com/hyperledger/fabric/blob/2736b63f8fd5932511d56fe68b7039d15977f7f6/core/ledger/kvledger/txmgmt/statedb/statecouchdb/couchdb.go#L779-L815","documentation":"CouchDB attachments may be gzip-compressed (Content-Encoding: gzip). While decoding a multipart attachment, gzip.NewReader failed, meaning the part bytes are not a valid gzip stream despite being advertised as gzip.","triggerScenarios":"Reading an attachment whose part claims Content-Encoding gzip but whose payload is corrupt, truncated, or not actually gzipped — e.g. data written by a different version/tooling or corrupted in storage.","commonSituations":"Corrupted attachments in the CouchDB database; proxy rewriting/compressing responses incorrectly; mismatch between how attachment was stored (compress:false) and read.","solutions":["Verify the attachment data in CouchDB directly (curl the attachment URL) to see if it is valid gzip","Re-write the attachment or restore the affected document from a backup","Check intermediaries (proxies) that might alter Content-Encoding or bodies","Compare Fabric/CouchDB versions between environments if data was migrated"],"exampleFix":"// validation before storing\nvar buf bytes.Buffer\nzw := gzip.NewWriter(&buf)\nzw.Write(attachmentBytes)\nzw.Close()\n// confirm round-trip\nzr, err := gzip.NewReader(bytes.NewReader(buf.Bytes()))\nif err != nil { return errors.New(\"attachment gzip payload invalid\") }","handlingStrategy":"validation","validationCode":"br := bufio.NewReader(partBytes)\nmagic, _ := br.Peek(2)\nif len(magic) < 2 || magic[0] != 0x1f || magic[1] != 0x8b {\n    return errors.New(\"attachment bytes are not gzip despite gzip Content-Encoding\")\n}","typeGuard":"func isGzip(b []byte) bool {\n    return len(b) >= 2 && b[0] == 0x1f && b[1] == 0x8b\n}","tryCatchPattern":"if err != nil && strings.Contains(err.Error(), \"error creating gzip reader\") {\n    return fmt.Errorf(\"attachment corrupted in CouchDB: %w; restore document from backup\", err)\n}","preventionTips":["Validate attachment payloads (gzip magic bytes) before storing via chaincode","Back up CouchDB data; test restores","Ensure proxies do not alter Content-Encoding or bodies","Keep Fabric/CouchDB versions consistent across environments"],"tags":["couchdb","gzip","compression","attachment"],"backgroundTag":"invalid-gzip-data","analyzedSha":"2736b63f8fd5932511d56fe68b7039d15977f7f6","analyzedAt":"2026-09-04T08:52:36.465Z","contentChangedAt":"2026-09-04T08:52:36.465Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}