cilium/cilium · error

failed to open ZIP file %s: %w

Error message

failed to open ZIP file %s: %w

What it means

extractZip opens the artifact with zip.OpenReader. If the file cannot be opened as a valid ZIP archive, this error reports the offending path plus the underlying cause.

Source

Thrown at cilium-cli/features/summary.go:224

		// Extract the ZIP file to the destination directory
		err = extractZip(tempFile, destDir)
		if err != nil {
			return fmt.Errorf("failed to extract artifact %s: %w", tempFile, err)
		}

		// Clean up the temporary ZIP file
		os.Remove(tempFile)
	}

	return nil
}

// extractZip extracts the contents of a ZIP file to a specified directory.
func extractZip(zipPath, destDir string) error {
	r, err := zip.OpenReader(zipPath)
	if err != nil {
		return fmt.Errorf("failed to open ZIP file %s: %w", zipPath, err)
	}
	defer r.Close()

	for _, file := range r.File {
		// Sanitize file.Name to prevent directory traversal
		cleanName := filepath.Clean(file.Name)
		if strings.Contains(cleanName, "..") || filepath.IsAbs(cleanName) {
			return fmt.Errorf("invalid file path in ZIP archive: %s", file.Name)
		}
		destPath := filepath.Join(destDir, cleanName)
		if !strings.HasPrefix(destPath, filepath.Clean(destDir)+string(os.PathSeparator)) {
			return fmt.Errorf("file path escapes destination directory: %s", destPath)
		}

		if file.FileInfo().IsDir() {
			// Create directories
			if err := os.MkdirAll(destPath, os.ModePerm); err != nil {
				return fmt.Errorf("failed to create directory %s: %w", destPath, err)

View on GitHub (pinned to ac7b90affa)

Solutions

  1. Verify the file is a real ZIP: run unzip -t on the reported path
  2. Re-download the artifact to fix truncation or corruption
  3. Check file permissions on the temp file/directory
  4. Confirm the server returned the artifact, not an HTML error page
Defensive patterns

Strategy: validation

Validate before calling

func looksLikeZip(p string) bool {
	f, err := os.Open(p)
	if err != nil { return false }
	defer f.Close()
	var magic [4]byte
	if _, err := io.ReadFull(f, magic[:]); err != nil { return false }
	return magic[0] == 'P' && magic[1] == 'K'
}

Try / catch

if err := extractZip(zipPath, destDir); err != nil {
	var pathErr *fs.PathError
	if errors.As(err, &pathErr) {
		// handle missing/unreadable file
	}
	return err
}

Prevention

When it happens

Trigger: zip.OpenReader(zipPath) fails because the file is missing, unreadable, or not a valid ZIP (bad magic bytes / corrupt central directory).

Common situations: A previous download left a truncated temp file; HTML error page saved instead of a ZIP; permission denied on the temp file.

Related errors


AI-assisted analysis of cilium/cilium@ac7b90affa (2026-08-31). Data as JSON: /api/errors/851b90f1c32513e5. Report an issue: GitHub.