{"record":{"id":"a03ce0e25abb6206","repo":"golang/go","slug":"errmissdata","errorCode":"errMissData","errorMessage":"archive/tar: sparse file references non-existent data","messagePattern":"archive/tar: sparse file references non-existent data","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/archive/tar/common.go","lineNumber":39,"sourceCode":"\t\"reflect\"\n\t\"strconv\"\n\t\"strings\"\n\t\"time\"\n)\n\n// BUG: Use of the Uid and Gid fields in Header could overflow on 32-bit\n// architectures. If a large value is encountered when decoding, the result\n// stored in Header will be the truncated version.\n\nvar tarinsecurepath = godebug.New(\"tarinsecurepath\")\n\nvar (\n\tErrHeader          = errors.New(\"archive/tar: invalid tar header\")\n\tErrWriteTooLong    = errors.New(\"archive/tar: write too long\")\n\tErrFieldTooLong    = errors.New(\"archive/tar: header field too long\")\n\tErrWriteAfterClose = errors.New(\"archive/tar: write after close\")\n\tErrInsecurePath    = errors.New(\"archive/tar: insecure file path\")\n\terrMissData        = errors.New(\"archive/tar: sparse file references non-existent data\")\n\terrUnrefData       = errors.New(\"archive/tar: sparse file contains unreferenced data\")\n\terrWriteHole       = errors.New(\"archive/tar: write non-NUL byte in sparse hole\")\n\terrSparseTooLong   = errors.New(\"archive/tar: sparse map too long\")\n)\n\ntype headerError []string\n\nfunc (he headerError) Error() string {\n\tconst prefix = \"archive/tar: cannot encode header\"\n\tvar ss []string\n\tfor _, s := range he {\n\t\tif s != \"\" {\n\t\t\tss = append(ss, s)\n\t\t}\n\t}\n\tif len(ss) == 0 {\n\t\treturn prefix\n\t}","sourceCodeStart":21,"sourceCodeEnd":57,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/src/archive/tar/common.go#L21-L57","documentation":"errMissData (unexported) is returned by the sparse-file reader and writer when the sparse map declares holes that reference byte ranges beyond the file's total Size, i.e. the dense data stream does not provide enough bytes to fill the declared data fragments. It indicates an internally inconsistent sparse entry.","triggerScenarios":"Reading a sparse tar entry whose sparse map's data fragments sum to more than Header.Size (the dense data is shorter than the map requires); writing a sparse entry where the caller-provided data is shorter than the sum of the sparse data fragments declared.","commonSituations":"Corrupted sparse archive from a faulty producer; truncated download of a sparse tar; manually constructed Header with a sparse map that disagrees with Size or with the bytes actually written.","solutions":["Re-acquire the archive from a trusted source and verify its checksum.","When constructing sparse headers, ensure sum(sparseDataFragments) == Header.Size and that you write exactly that many bytes.","Skip or quarantine the entry on errMissData rather than retrying — the format is internally inconsistent.","If reading untrusted archives, treat any unexported tar error as corruption and log the entry name for triage."],"exampleFix":"// before\nhdr := &tar.Header{\n  Size:  10,\n  Sparses: []tar.SparseEntry{{Offset: 0, NumBytes: 20}}, // mismatch\n}\ntw.WriteHeader(hdr)\ntw.Write(make([]byte, 10)) // throws errMissData\n\n// after\nhdr := &tar.Header{\n  Size:  20,\n  Sparses: []tar.SparseEntry{{Offset: 0, NumBytes: 20}},\n}\ntw.WriteHeader(hdr)\ntw.Write(make([]byte, 20))","handlingStrategy":"validation","validationCode":"var sum int64\nfor _, s := range hdr.Sparses { sum += s.NumBytes }\nif sum != hdr.Size {\n  return fmt.Errorf(\"sparse fragments sum %d != Size %d\", sum, hdr.Size)\n}","typeGuard":null,"tryCatchPattern":"if _, err := tr.Read(buf); errors.Is(err, tar.errMissData) || strings.Contains(err.Error(), \"sparse file references non-existent data\") {\n  log.Printf(\"corrupt sparse entry %q; skipping\", hdr.Name)\n  continue\n}","preventionTips":["When authoring sparse entries, ensure sum(sparse fragments) == Header.Size.","Verify checksums of untrusted archives before extraction.","Quarantine entries that fail sparse consistency checks rather than retrying."],"tags":["archive-tar","sparse","validation","corruption","reader","writer"],"analyzedSha":"b6b368adc57c96c3151d224d172029f233ead2c3","analyzedAt":"2026-08-12T00:22:02.250Z","schemaVersion":2},"datasetVersion":"2026-08-12T06:17:24.410Z"}