golang/go · error
file larger than size reported by stat
Error message
file larger than size reported by stat
What it means
While assembling an ar-format archive of object files, the go command writes each file preceded by a header whose size field comes from a prior stat. After io.Copy it checks the copied byte count against that size; if more bytes were read than stat reported (n > size), the file grew between stat and read - a race where the object file was modified concurrently.
Source
Thrown at src/cmd/go/internal/work/gc.go:525
return err
}
// Note: Not using %-16.16s format because we care
// about bytes, not runes.
name := fi.Name()
if len(name) > 16 {
name = name[:16]
} else {
name += strings.Repeat(" ", 16-len(name))
}
size := fi.Size()
fmt.Fprintf(w, "%s%-12d%-6d%-6d%-8o%-10d`\n",
name, 0, 0, 0, 0644, size)
n, err := io.Copy(w, src)
src.Close()
if err == nil && n < size {
err = io.ErrUnexpectedEOF
} else if err == nil && n > size {
err = fmt.Errorf("file larger than size reported by stat")
}
if err != nil {
return fmt.Errorf("copying %s to %s: %v", ofile, afile, err)
}
if size&1 != 0 {
w.WriteByte(0)
}
}
if err := w.Flush(); err != nil {
return err
}
return dst.Close()
}
// setextld sets the appropriate linker flags for the specified compiler.
func setextld(ldflags []string, compiler []string) ([]string, error) {
for _, f := range ldflags {View on GitHub (pinned to b6b368adc5)
Solutions
- Ensure no concurrent process modifies object files during a go build
- Re-run the build - transient races often do not recur
- Move the build to a local filesystem if using NFS/FUSE
Example fix
// before (generator races with go build) go generate & go build // after (sequential) go generate && go build
Defensive patterns
Strategy: retry
Try / catch
// A transient race: retry the build once
if bytes.Contains(out, []byte("file larger than size reported by stat")) {
out, err = cmd.CombinedOutput()
} Prevention
- Never run generators or concurrent builds that write the same object files
- Build on a local filesystem, not NFS/FUSE
- Sequence `go generate` before `go build` rather than in parallel
When it happens
Trigger: Fires in the archive-assembly code of gc.go when io.Copy returns n > size, where size = fi.Size() from the earlier os.Stat on the object file.
Common situations: A code generator or concurrent go build writing the object file mid-archive, a FUSE filesystem with inconsistent stat/read, or a network filesystem with caching lag.
Related errors
- copying %s to %s: %v
- corrupt archive
- truncated archive
- archive/tar: sockets not supported
- archive/tar: unknown file mode %v
AI-assisted analysis of golang/go@b6b368adc5 (2026-08-12).
Data as JSON: /api/errors/db734a7df22e01ac.
Report an issue: GitHub.