{"record":{"id":"d11ca51b8ea876b5","repo":"hyperledger/fabric","slug":"failure-opening-codepackage-gzip-stream-s-d11ca5","errorCode":null,"errorMessage":"failure opening codepackage gzip stream: %s","messagePattern":"failure opening codepackage gzip stream: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/chaincode/platforms/java/platform.go","lineNumber":53,"sourceCode":"// ValidatePath validates the java chaincode paths\nfunc (p *Platform) ValidatePath(rawPath string) error {\n\tpath, err := url.Parse(rawPath)\n\tif err != nil || path == nil {\n\t\tlogger.Errorf(\"invalid chaincode path %s %v\", rawPath, err)\n\t\treturn fmt.Errorf(\"invalid path: %s\", err)\n\t}\n\n\treturn nil\n}\n\nfunc (p *Platform) ValidateCodePackage(code []byte) error {\n\t// File to be valid should match first RegExp and not match second one.\n\tfilesToMatch := regexp.MustCompile(`^(/)?src/((src|META-INF)/.*|(build\\.gradle|settings\\.gradle|pom\\.xml))`)\n\tfilesToIgnore := regexp.MustCompile(`.*\\.class$`)\n\tis := bytes.NewReader(code)\n\tgr, err := gzip.NewReader(is)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failure opening codepackage gzip stream: %s\", err)\n\t}\n\ttr := tar.NewReader(gr)\n\n\tfor {\n\t\theader, err := tr.Next()\n\t\tif err == io.EOF {\n\t\t\tbreak\n\t\t}\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\n\t\t// --------------------------------------------------------------------------------------\n\t\t// Check name for conforming path\n\t\t// --------------------------------------------------------------------------------------\n\t\tif !filesToMatch.MatchString(header.Name) || filesToIgnore.MatchString(header.Name) {\n\t\t\treturn fmt.Errorf(\"illegal file detected in payload: \\\"%s\\\"\", header.Name)\n\t\t}","sourceCodeStart":35,"sourceCodeEnd":71,"githubUrl":"https://github.com/hyperledger/fabric/blob/2736b63f8fd5932511d56fe68b7039d15977f7f6/core/chaincode/platforms/java/platform.go#L35-L71","documentation":"ValidateCodePackage for the Java platform expects the chaincode package to be a gzip-compressed tar archive. It immediately wraps the submitted bytes in a gzip reader; if the bytes are not valid gzip data, gzip.NewReader fails and this error is returned with the underlying cause appended.","triggerScenarios":"Calling ValidateCodePackage (directly or via chaincode install/package flows) with code bytes that are not gzip-compressed: raw tar, plain text, a zip file, a truncated or corrupt gzip stream, or empty bytes.","commonSituations":"Uploading an already-decompressed .tar instead of a .tgz; a packaging step that produced an empty or partial file; HTTP transfer corruption; mistakenly passing a zip archive created by IDE export tools.","solutions":["Repackage the chaincode as a gzip-compressed tar (tar -czf) and retry","Check the packaged file with `file mypackage.tgz` or `gzip -t` to confirm it is valid gzip","Regenerate the package so it is not truncated or empty","Ensure the transport path (HTTP upload, base64 encoding) does not corrupt binary data"],"exampleFix":"// before\npayload, _ := os.ReadFile(\"mypackage.tar\") // raw tar, not gzipped\nerr := platform.ValidateCodePackage(payload)\n// after\npayload, _ := os.ReadFile(\"mypackage.tgz\") // gzip-compressed tar\nerr := platform.ValidateCodePackage(payload)","handlingStrategy":"validation","validationCode":"func isValidGzip(data []byte) bool { r, err := gzip.NewReader(bytes.NewReader(data)); return err == nil && r != nil }\nif !isValidGzip(payload) { return errors.New(\"package is not a valid gzip archive\") }","typeGuard":null,"tryCatchPattern":"err := platform.ValidateCodePackage(code)\nif err != nil && strings.Contains(err.Error(), \"failure opening codepackage gzip stream\") {\n    // regenerate/repair package; not retryable against same input\n}","preventionTips":["Always create packages with tar -czf or the SDK's packaging APIs","Run gzip -t on the artifact before submitting","Never re-save or re-encode the package through text transformations"],"tags":["chaincode","java","gzip","packaging"],"backgroundTag":"invalid-archive-format","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"}