goharbor/harbor · error

failed to read tar header: %w

Error message

failed to read tar header: %w

What it means

Error "failed to read tar header: %w" thrown in goharbor/harbor.

Source

Thrown at src/controller/artifact/processor/cnai/parser/util.go:80

	if limit < 0 {
		return nil, fmt.Errorf("invalid limit: %d", limit)
	}

	// Cap the raw bytes consumed from the underlying stream as well: the
	// manifest-declared blob size can lie, and tar.Reader.Next() materializes
	// metadata (PAX extended records, GNU sparse maps) in memory before the
	// per-entry content copy below ever sees it.
	tr := tar.NewReader(&limitedReader{r: reader, remaining: limit + maxTarMetadataOverhead})
	var buf bytes.Buffer
	remaining := limit
	for {
		header, err := tr.Next()
		if err == io.EOF {
			break
		}

		if err != nil {
			return nil, fmt.Errorf("failed to read tar header: %w", err)
		}

		// skip the directory.
		if header.Typeflag == tar.TypeDir {
			continue
		}

		// Copy at most remaining+1 bytes so we can detect when the cumulative
		// content exceeds the limit without trusting the declared header size.
		n, err := io.Copy(&buf, io.LimitReader(tr, remaining+1))
		if err != nil {
			return nil, fmt.Errorf("failed to copy content to buffer: %w", err)
		}

		remaining -= n
		if remaining < 0 {
			return nil, errors.RequestEntityTooLargeError(errFileTooLarge)
		}

View on GitHub (pinned to 7b2fd08cc5)

When it happens

Trigger: Thrown at src/controller/artifact/processor/cnai/parser/util.go:80 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of goharbor/harbor@7b2fd08cc5 (2026-08-16). Data as JSON: /api/errors/b8a51c7bb5f14f5d. Report an issue: GitHub.