{"record":{"id":"b608d7966d93a67e","repo":"hyperledger/fabric","slug":"error-reading-gzip-data","errorCode":null,"errorMessage":"error reading gzip data","messagePattern":"error reading gzip data","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/ledger/kvledger/txmgmt/statedb/statecouchdb/couchdb.go","lineNumber":801,"sourceCode":"\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\")\n\t\t\t}\n\t\t\tcouchdbLogger.Debugf(\"[%s] Retrieved attachment data\", dbclient.dbName)\n\t\t\tattachment.AttachmentBytes = partdata\n\t\t\tattachment.Length = uint64(len(attachment.AttachmentBytes))","sourceCodeStart":783,"sourceCodeEnd":819,"githubUrl":"https://github.com/hyperledger/fabric/blob/2736b63f8fd5932511d56fe68b7039d15977f7f6/core/ledger/kvledger/txmgmt/statedb/statecouchdb/couchdb.go#L783-L819","documentation":"After successfully opening a gzip reader for a compressed CouchDB attachment part, io.ReadAll(gr) failed while decompressing the body. This means the gzip stream started validly but was corrupt or truncated partway through.","triggerScenarios":"Reading a gzip-encoded attachment whose compressed bytes are truncated or corrupted: interrupted writes to CouchDB, disk corruption, or stream cut off by network failure.","commonSituations":"Partial attachment uploads; corrupted CouchDB database files after unclean shutdown; proxies truncating large compressed bodies.","solutions":["Re-fetch the attachment; if the error persists, the stored data is corrupt","Restore the affected document/attachment from backup or re-upload it via the chaincode","Run integrity checks on CouchDB storage (disk health, database compaction)","Check for intermediaries truncating large responses and raise body limits"],"exampleFix":"// before (store unverified compressed bytes)\nattachment.AttachmentBytes = compressedBytes\n// after (verify before storing)\nzr, err := gzip.NewReader(bytes.NewReader(compressedBytes))\nif err != nil || len(compressedBytes) == 0 {\n    return errors.New(\"refusing to store invalid/truncated gzip attachment\")\n}\nattachment.AttachmentBytes = compressedBytes","handlingStrategy":"try-catch","validationCode":"zr, err := gzip.NewReader(bytes.NewReader(storedAttachment))\nif err != nil { return errors.New(\"stored attachment is not valid gzip\") }\nif _, err := io.ReadAll(zr); err != nil { return errors.New(\"stored gzip attachment is truncated/corrupt\") }","typeGuard":null,"tryCatchPattern":"if err != nil && strings.Contains(err.Error(), \"error reading gzip data\") {\n    return fmt.Errorf(\"truncated/corrupt gzip attachment: %w; re-upload attachment via chaincode\", err)\n}","preventionTips":["Verify uploads complete (checksums) before accepting attachments","Run disk health monitoring on CouchDB storage volumes","Gracefully shut down CouchDB to avoid truncated writes","Compact and validate the database after unclean shutdowns"],"tags":["couchdb","gzip","corruption","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"}