{"record":{"id":"764b44404330294c","repo":"valyala/fasthttp","slug":"too-big-file-d-bytes","errorCode":null,"errorMessage":"too big file: %d bytes","messagePattern":"too big file: (.+?) bytes","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"fs.go","lineNumber":1937,"sourceCode":"\t\t// On macOS the gzip seems to truncate the nanoseconds in the mod time causing the original file\n\t\t// to look newer than the gzipped file.\n\t\tif fileInfoOriginal.ModTime().Sub(fileInfo.ModTime()) >= time.Second {\n\t\t\t// The compressed file became stale. Re-create it.\n\t\t\t_ = f.Close()\n\t\t\t_ = os.Remove(filePath)\n\t\t\treturn h.compressAndOpenFSFile(filePathOriginal, fileEncoding)\n\t\t}\n\t}\n\n\treturn h.newFSFile(f, fileInfo, mustCompress, filePath, fileEncoding)\n}\n\nfunc (h *fsHandler) newFSFile(f fs.File, fileInfo fs.FileInfo, compressed bool, filePath, fileEncoding string) (*fsFile, error) {\n\tn := fileInfo.Size()\n\tcontentLength := int(n)\n\tif n != int64(contentLength) {\n\t\t_ = f.Close()\n\t\treturn nil, fmt.Errorf(\"too big file: %d bytes\", n)\n\t}\n\n\t// detect content-type\n\text := fileExtension(fileInfo.Name(), compressed, h.compressedFileSuffixes[fileEncoding])\n\tcontentType := mime.TypeByExtension(ext)\n\tif contentType == \"\" {\n\t\tdata, err := readFileHeader(f, compressed, fileEncoding)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"cannot read header of the file %q: %w\", fileInfo.Name(), err)\n\t\t}\n\t\tcontentType = http.DetectContentType(data)\n\t}\n\n\tlastModified := fileInfo.ModTime()\n\tff := &fsFile{\n\t\th:               h,\n\t\tf:               f,\n\t\tfilename:        filePath,","sourceCodeStart":1919,"sourceCodeEnd":1955,"githubUrl":"https://github.com/valyala/fasthttp/blob/c96f600972c6f4a7a30d664257b340ebe9d60124/fs.go#L1919-L1955","documentation":"newFSFile rejects files whose size does not fit into an int (int(n) != int64(n)) because content-length and buffering are tracked as int. On 32-bit builds this fires for files larger than ~2 GiB; on 64-bit builds practically never.","triggerScenarios":"Serving a file via FS/SendFile whose fs.FileInfo.Size() exceeds the platform int range — typically >2,147,483,647 bytes on a 32-bit (GOARCH=386/arm) binary.","commonSituations":"Hosting large videos/archives (>2GB) with fasthttp compiled for 32-bit platforms; embedded/arm devices serving big media.","solutions":["Build for a 64-bit platform (GOARCH=amd64/arm64)","Serve the big file via a different mechanism (e.g. http.ServeFile from net/http, or streaming manually)","Split or reduce the file below 2 GiB"],"exampleFix":"// before\nGOOS=linux GOARCH=386 go build ./cmd/server\n// after\nGOOS=linux GOARCH=amd64 go build ./cmd/server","handlingStrategy":"validation","validationCode":"if fi, err := os.Stat(path); err == nil && fi.Size() > math.MaxInt32 { /* too big for 32-bit int; use another serving path */ }","typeGuard":null,"tryCatchPattern":"if err := ctx.SendFile(bigPath); err != nil { if strings.HasPrefix(err.Error(), \"too big file\") { stream manually } }","preventionTips":["Use 64-bit builds (amd64/arm64) for servers","Add file-size checks in upload pipelines","For >2GiB files, stream via manual chunked responses"],"tags":["filesystem","fasthttp","int-overflow","static-files"],"backgroundTag":"file-too-large","analyzedSha":"c96f600972c6f4a7a30d664257b340ebe9d60124","analyzedAt":"2026-08-31T22:48:28.265Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}