{"record":{"id":"d46573f1b1f131d1","repo":"golang/go","slug":"file-too-large-d-bytes-d-bytes","errorCode":null,"errorMessage":"file too large (%d bytes > %d bytes)","messagePattern":"file too large \\((.+?) bytes > (.+?) bytes\\)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cmd/compile/internal/staticdata/data.go","lineNumber":161,"sourceCode":"\t\t}\n\t\tvar sym *obj.LSym\n\t\tif readonly {\n\t\t\tsym = StringSym(pos, string(data))\n\t\t} else {\n\t\t\tsym = slicedata(pos, string(data))\n\t\t}\n\t\tif len(hashBytes) > 0 {\n\t\t\tsum := hash.Sum32(data)\n\t\t\tcopy(hashBytes, sum[:])\n\t\t}\n\t\treturn sym, size, nil\n\t}\n\tif size > maxFileSize {\n\t\t// ggloblsym takes an int32,\n\t\t// and probably the rest of the toolchain\n\t\t// can't handle such big symbols either.\n\t\t// See golang.org/issue/9862.\n\t\treturn nil, 0, fmt.Errorf(\"file too large (%d bytes > %d bytes)\", size, maxFileSize)\n\t}\n\n\t// File is too big to read and keep in memory.\n\t// Compute hashBytes if needed for read-only content hashing or if the caller wants it.\n\tvar sum []byte\n\tif readonly || len(hashBytes) > 0 {\n\t\th := hash.New32()\n\t\tn, err := io.Copy(h, f)\n\t\tif err != nil {\n\t\t\treturn nil, 0, err\n\t\t}\n\t\tif n != size {\n\t\t\treturn nil, 0, fmt.Errorf(\"file changed between reads\")\n\t\t}\n\t\tsum = h.Sum(nil)\n\t\tcopy(hashBytes, sum)\n\t}\n","sourceCodeStart":143,"sourceCodeEnd":179,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/src/cmd/compile/internal/staticdata/data.go#L143-L179","documentation":"The Go toolchain imposes a maximum symbol size of obj.MaxSymSize (2GB, defined as int64(2e9) in cmd/internal/obj). When an embedded file exceeds this limit, the compiler rejects it with this error showing the actual size and the limit. This is a hard constraint of the object file format.","triggerScenarios":"Attempting to //go:embed a file larger than 2GB. The size is determined by os.FileInfo.Size() from stat, so sparse files may also trigger this if their reported size exceeds the limit.","commonSituations":"Accidentally embedding large data files (SQLite databases, video, ML model weights, large datasets). Not realizing that //go:embed loads the entire file into the compiled binary. Using embed.FS with a directory containing very large files.","solutions":["Do not embed files larger than 2GB — load them at runtime with os.Open or os.ReadFile","Split large files into chunks under the limit and embed each chunk separately","Use a content-addressed external storage strategy and download large assets at install or runtime","Review your embed patterns to ensure they don't accidentally match large files"],"exampleFix":"// before\n//go:embed assets/large_model.bin (3GB)\nvar modelData []byte\n\n// after — load at runtime\nfunc loadModel() ([]byte, error) {\n    return os.ReadFile(filepath.Join(assetDir, \"large_model.bin\"))\n}","handlingStrategy":"validation","validationCode":"// Check embedded file sizes against the 2GB limit\nconst maxEmbedSize = int64(2e9) // obj.MaxSymSize\n\nfunc checkEmbedFileSizes(dir string) error {\n    return filepath.Walk(dir, func(path string, info os.FileInfo, err error) error {\n        if err != nil {\n            return err\n        }\n        if !info.IsDir() && info.Size() > maxEmbedSize {\n            return fmt.Errorf(\"%s is %d bytes, exceeds embed limit of %d bytes — use runtime loading instead\", path, info.Size(), maxEmbedSize)\n        }\n        return nil\n    })\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never embed files larger than 2GB — load them at runtime instead","Review embed patterns to ensure they don't accidentally match large files","Use .embedignore or directory structure to exclude large data files from embed patterns","Consider compressing large files before embedding if they must be in the binary"],"tags":["go-compiler","go-embed","file-system","size-limit","resource-constraint"],"analyzedSha":"b6b368adc57c96c3151d224d172029f233ead2c3","analyzedAt":"2026-08-12T00:22:02.250Z","schemaVersion":2},"datasetVersion":"2026-08-12T06:17:24.410Z"}