goharbor/harbor · error

failed to read tar header

Error message

failed to read tar header: %w

What it means

Wrapping error from untar in the CNAI parser util: tar.Reader.Next returned a non-EOF error while iterating tar entries, meaning the stream is not a valid tar archive or is truncated/corrupted mid-header.

Solutions

  1. Re-push the artifact - the tar blob is likely corrupted or truncated.
  2. Confirm the layer media type is actually tar before decoding.
  3. Check whether the limited reader cut the stream short (size limit hit before EOF).
Defensive patterns

Strategy: try-catch

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.

Appendix: 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)