hyperledger/fabric · error

failure opening codepackage gzip stream: %s

Error message

failure opening codepackage gzip stream: %s

What it means

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.

Source

Thrown at core/chaincode/platforms/java/platform.go:53

// ValidatePath validates the java chaincode paths
func (p *Platform) ValidatePath(rawPath string) error {
	path, err := url.Parse(rawPath)
	if err != nil || path == nil {
		logger.Errorf("invalid chaincode path %s %v", rawPath, err)
		return fmt.Errorf("invalid path: %s", err)
	}

	return nil
}

func (p *Platform) ValidateCodePackage(code []byte) error {
	// File to be valid should match first RegExp and not match second one.
	filesToMatch := regexp.MustCompile(`^(/)?src/((src|META-INF)/.*|(build\.gradle|settings\.gradle|pom\.xml))`)
	filesToIgnore := regexp.MustCompile(`.*\.class$`)
	is := bytes.NewReader(code)
	gr, err := gzip.NewReader(is)
	if err != nil {
		return fmt.Errorf("failure opening codepackage gzip stream: %s", err)
	}
	tr := tar.NewReader(gr)

	for {
		header, err := tr.Next()
		if err == io.EOF {
			break
		}
		if err != nil {
			return err
		}

		// --------------------------------------------------------------------------------------
		// Check name for conforming path
		// --------------------------------------------------------------------------------------
		if !filesToMatch.MatchString(header.Name) || filesToIgnore.MatchString(header.Name) {
			return fmt.Errorf("illegal file detected in payload: \"%s\"", header.Name)
		}

View on GitHub (pinned to 2736b63f8f)

Solutions

  1. Repackage the chaincode as a gzip-compressed tar (tar -czf) and retry
  2. Check the packaged file with `file mypackage.tgz` or `gzip -t` to confirm it is valid gzip
  3. Regenerate the package so it is not truncated or empty
  4. Ensure the transport path (HTTP upload, base64 encoding) does not corrupt binary data

Example fix

// before
payload, _ := os.ReadFile("mypackage.tar") // raw tar, not gzipped
err := platform.ValidateCodePackage(payload)
// after
payload, _ := os.ReadFile("mypackage.tgz") // gzip-compressed tar
err := platform.ValidateCodePackage(payload)
Defensive patterns

Strategy: validation

Validate before calling

func isValidGzip(data []byte) bool { r, err := gzip.NewReader(bytes.NewReader(data)); return err == nil && r != nil }
if !isValidGzip(payload) { return errors.New("package is not a valid gzip archive") }

Try / catch

err := platform.ValidateCodePackage(code)
if err != nil && strings.Contains(err.Error(), "failure opening codepackage gzip stream") {
    // regenerate/repair package; not retryable against same input
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of hyperledger/fabric@2736b63f8f (2026-09-04). Data as JSON: /api/errors/d11ca51b8ea876b5. Report an issue: GitHub.