hyperledger/fabric · error
failure opening codepackage gzip stream: %s
Error message
failure opening codepackage gzip stream: %s
What it means
Platform.ValidateCodePackage treats an install package as a gzip-compressed tar; it wraps gzip.NewReader failure with 'failure opening codepackage gzip stream: %s'. The submitted package bytes are not valid gzip, so validation fails before any tar inspection.
Source
Thrown at core/chaincode/platforms/golang/platform.go:80
}
// not a module
if modInfo == nil {
return rawPath, nil
}
return modInfo.ImportPath, nil
}
// ValidateCodePackage examines the chaincode archive to ensure it is valid.
//
// NOTE: this code is used in some transaction validation paths but can be changed
// post 2.0.
func (p *Platform) ValidateCodePackage(code []byte) error {
is := bytes.NewReader(code)
gr, err := gzip.NewReader(is)
if err != nil {
return fmt.Errorf("failure opening codepackage gzip stream: %s", err)
}
re := regexp.MustCompile(`^(src|META-INF)/`)
tr := tar.NewReader(gr)
for {
header, err := tr.Next()
if err == io.EOF {
break
}
if err != nil {
return err
}
// maintain check for conforming paths for validation
if !re.MatchString(header.Name) {
return fmt.Errorf("illegal file name in payload: %s", header.Name)
}
View on GitHub (pinned to 2736b63f8f)
Solutions
- Package the chaincode as gzip: 'tar czf code.tar.gz src/...' and resubmit
- Verify the payload starts with gzip magic bytes 1f 8b before submitting
- Check the client packaging code path — use the platform's GetDeploymentPayload rather than hand-rolled tars
- If the package came from a transfer, re-download and compare hashes to rule out truncation
Example fix
// before tar -cf code.tar src/ // after tar -czf code.tar.gz src/
Defensive patterns
Strategy: validation
Validate before calling
func isGzip(b []byte) bool { return len(b) > 2 && b[0] == 0x1f && b[1] == 0x8b }
if !isGzip(code) { return errors.New("package is not gzip") }
if _, err := gzip.NewReader(bytes.NewReader(code)); err != nil { return err } Type guard
func isGzip(b []byte) bool { return len(b) > 2 && b[0] == 0x1f && b[1] == 0x8b } Try / catch
if err := platform.ValidateCodePackage(code); err != nil {
if strings.Contains(err.Error(), "failure opening codepackage gzip stream") {
return fmt.Errorf("repackage as tar.gz: %w", err)
}
return err
} Prevention
- Always package with tar -czf
- Validate gzip magic bytes client-side before submit
- Use the platform's GetDeploymentPayload for packaging
- Compare checksums after network transfer
When it happens
Trigger: Calling ValidateCodePackage(code) (used in some transaction validation paths pre-2.0) with bytes that are not gzip: empty payload, raw tar, plain files, or truncated/corrupt gzip stream.
Common situations: Uploading an uncompressed .tar instead of .tar.gz; corrupted package over the network; client SDK packaging bug; Fabric 1.4-era validation path fed a 2.x-style (non-gzip-shaped) package.
Related errors
- %s is mandatory and cannot be empty
- enrollment certificate isn't a valid PEM block
- failed to decode PEM block from %s
- could not create channel %s sub-group config
- config ID illegal, cannot be empty
AI-assisted analysis of hyperledger/fabric@2736b63f8f (2026-09-04).
Data as JSON: /api/errors/a5f83886b0eb9112.
Report an issue: GitHub.