anomalyco/sst · error

failed to create gzip reader: %w

Error message

failed to create gzip reader: %w

What it means

After opening the file, extractTarGz calls gzip.NewReader, which reads the gzip magic header. If the file is not actually gzip-compressed (or is truncated/corrupt), the error is wrapped as "failed to create gzip reader". This catches cases where the downloaded file is an HTML error page, a plain wheel/zip, or a partially downloaded archive.

Source

Thrown at pkg/runtime/python/build.go:407

			return err
		}
		out.Close()
		rc.Close()
	}
	return nil
}

// extractTarGz extracts a .tar.gz archive to the destination directory.
func extractTarGz(archiveFile, destDir string) error {
	f, err := os.Open(archiveFile)
	if err != nil {
		return fmt.Errorf("failed to open archive: %w", err)
	}
	defer f.Close()

	gz, err := gzip.NewReader(f)
	if err != nil {
		return fmt.Errorf("failed to create gzip reader: %w", err)
	}
	defer gz.Close()

	tr := tar.NewReader(gz)
	for {
		hdr, err := tr.Next()
		if err == io.EOF {
			break
		}
		if err != nil {
			return fmt.Errorf("failed to read tar entry: %w", err)
		}

		target := filepath.Join(destDir, hdr.Name)
		// Guard against tar slip
		if !strings.HasPrefix(filepath.Clean(target), filepath.Clean(destDir)+string(os.PathSeparator)) {
			return fmt.Errorf("illegal file path in tar: %s", hdr.Name)
		}

View on GitHub (pinned to a0bd20f762)

Solutions

  1. Delete the corrupt archive and re-download it from the package index
  2. Check the download URL/mirror is correct and serves real .tar.gz content (curl -I / file on the artifact)
  3. Inspect the first bytes of the file (file archive.tar.gz or xxd) to confirm it is gzip data
  4. Disable or fix the proxy/cache that may be serving an error page
  5. Switch to a wheel (.whl) install path if the sdist download keeps failing

Example fix

// before: trusting a cached artifact
err := download(url, archiveFile)
extractTarGz(archiveFile, destDir)

// after: verify gzip magic bytes before extracting
data, _ := os.ReadFile(archiveFile)
if len(data) < 2 || data[0] != 0x1f || data[1] != 0x8b {
    os.Remove(archiveFile)
    return fmt.Errorf("%s is not gzip, re-downloading", archiveFile)
}
extractTarGz(archiveFile, destDir)
Defensive patterns

Strategy: validation

Validate before calling

f, err := os.Open(archiveFile)
if err != nil {
    return err
}
magic := make([]byte, 2)
io.ReadFull(f, magic)
f.Close()
if magic[0] != 0x1f || magic[1] != 0x8b {
    return fmt.Errorf("%s is not gzip data", archiveFile)
}

Try / catch

if err := extractTarGz(archiveFile, destDir); err != nil {
    if strings.Contains(err.Error(), "failed to create gzip reader") {
        os.Remove(archiveFile) // drop corrupt artifact and re-download
    }
    return err
}

Prevention

When it happens

Trigger: The file at archiveFile is not valid gzip data: the download server returned an HTML 404/login page, the URL returned a .zip instead of a .tar.gz, the download was truncated by a network failure, or the file is a plain (uncompressed) .tar.

Common situations: Proxy or captive portal intercepts the download and serves an HTML error page; a package index mirror is broken; pip resolved to an sdist but the cached artifact is corrupt; an interrupted CI download left a partial file that was cached.

Related errors


AI-assisted analysis of anomalyco/sst@a0bd20f762 (2026-08-30). Data as JSON: /api/errors/afc83b64a0fd32a6. Report an issue: GitHub.