{"record":{"id":"75feb49785eda492","repo":"golang/go","slug":"corrupt-archive","errorCode":null,"errorMessage":"corrupt archive","messagePattern":"corrupt archive","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cmd/internal/archive/archive.go","lineNumber":104,"sourceCode":"type GoObj struct {\n\tTextHeader []byte\n\tArch       string\n\tData\n}\n\nconst (\n\tentryHeader = \"%s%-12d%-6d%-6d%-8o%-10d`\\n\"\n\t// In entryHeader the first entry, the name, is always printed as 16 bytes right-padded.\n\tentryLen   = 16 + 12 + 6 + 6 + 8 + 10 + 1 + 1\n\ttimeFormat = \"Jan _2 15:04 2006\"\n)\n\nvar (\n\tarchiveHeader = []byte(\"!<arch>\\n\")\n\tarchiveMagic  = []byte(\"`\\n\")\n\tgoobjHeader   = []byte(\"go objec\") // truncated to size of archiveHeader\n\n\terrCorruptArchive   = errors.New(\"corrupt archive\")\n\terrTruncatedArchive = errors.New(\"truncated archive\")\n\terrCorruptObject    = errors.New(\"corrupt object file\")\n\terrNotObject        = errors.New(\"unrecognized object file format\")\n)\n\ntype ErrGoObjOtherVersion struct{ magic []byte }\n\nfunc (e ErrGoObjOtherVersion) Error() string {\n\treturn fmt.Sprintf(\"go object of a different version: %q\", e.magic)\n}\n\n// An objReader is an object file reader.\ntype objReader struct {\n\ta      *Archive\n\tb      *bio.Reader\n\terr    error\n\toffset int64\n\tlimit  int64","sourceCodeStart":86,"sourceCodeEnd":122,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/src/cmd/internal/archive/archive.go#L86-L122","documentation":"Defined as errCorruptArchive in cmd/internal/archive and returned by the archive reader when a Unix-style ar archive (the container format used by Go object files, static .a libraries) has a structurally invalid header — e.g. a malformed entry header, a bad magic, or a name/size field that does not parse. The Go linker and cmd/go read these archives when linking; this error means the file is not a valid ar container at all (as opposed to truncated, which is a different sentinel).","triggerScenarios":"Reading a file as a Go object archive when it is actually something else (a random binary, an ELF executable, a text file). An archive whose \"!<arch>\\n\" magic was corrupted or whose entry padding/magic backtick-newline is wrong. A truncated-then-overwritten file produced by a failed previous build.","commonSituations":"Build cache corruption from concurrent writers, disk full, or system crash mid-write. Manually editing or stripping object files. A third-party tool that writes .a files with a non-standard ar variant (e.g. GNU vs BSD long-name handling). Mixing object files from incompatible Go versions in rare cache-key collisions.","solutions":["Run `go clean -cache` to purge the build cache and rebuild from scratch.","If reading a specific .a file, verify it with `ar t file.a` (or `file file.a`) — if that also fails, the file is not a valid archive.","Recompile the package producing the bad archive from source to regenerate it.","Check disk health and disable any concurrent processes that write into GOPATH/pkg or the build cache."],"exampleFix":"# before\n$ go build ./...\n# -> corrupt archive\n\n# after\n$ go clean -cache\n$ go build ./...","handlingStrategy":"retry","validationCode":"// Cheap sanity check before passing a file to the archive reader:\nfunc looksLikeArchive(path string) error {\n    f, err := os.Open(path); if err != nil { return err }\n    defer f.Close()\n    var hdr [8]byte\n    if _, err := io.ReadFull(f, hdr[:]); err != nil { return err }\n    if string(hdr[:]) != \"!<arch>\\n\" { return errors.New(\"not an ar archive\") }\n    return nil\n}","typeGuard":"func isArArchive(path string) bool { return looksLikeArchive(path) == nil }","tryCatchPattern":"// On corrupt/truncated archive errors, purge the build cache entry and retry once.\nif err != nil && (errors.Is(err, archive.ErrCorruptArchive) || strings.Contains(err.Error(), \"corrupt archive\")) {\n    _ = os.Remove(cachePath)\n    // rebuild\n}","preventionTips":["Keep GOCACHE on reliable local storage, not a network filesystem.","Do not share a single GOCACHE across Go versions.","Run `go clean -cache` after Go upgrades."],"tags":["go-toolchain","archive","linker","corruption","build-cache"],"analyzedSha":"b6b368adc57c96c3151d224d172029f233ead2c3","analyzedAt":"2026-08-12T00:22:02.250Z","schemaVersion":2},"datasetVersion":"2026-08-12T06:17:24.410Z"}