{"id":"87a1ae22cab8acd5","repo":"gofiber/fiber","slug":"favicon-read-limited-w","errorCode":null,"errorMessage":"favicon: read limited: %w","messagePattern":"favicon: read limited: %w","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"middleware/favicon/favicon.go","lineNumber":107,"sourceCode":"\t\t}\n\n\t\t// Serve cached favicon\n\t\tif iconLen > 0 {\n\t\t\tc.Set(fiber.HeaderContentLength, iconLenHeader)\n\t\t\tc.Set(fiber.HeaderContentType, hType)\n\t\t\tc.Set(fiber.HeaderCacheControl, cfg.CacheControl)\n\t\t\treturn c.Status(fiber.StatusOK).Send(iconData)\n\t\t}\n\n\t\treturn c.SendStatus(fiber.StatusNoContent)\n\t}\n}\n\nfunc readLimited(reader io.Reader, maxBytes int64) ([]byte, error) {\n\tlimit := maxBytes + 1\n\tdata, err := io.ReadAll(io.LimitReader(reader, limit))\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"favicon: read limited: %w\", err)\n\t}\n\tif int64(len(data)) > maxBytes {\n\t\treturn nil, fmt.Errorf(\"favicon: file size exceeds max bytes %d\", maxBytes)\n\t}\n\treturn data, nil\n}\n","sourceCodeStart":89,"sourceCodeEnd":114,"githubUrl":"https://github.com/gofiber/fiber/blob/9a4c7e57fe0b080a04235d28a4b0d2b4b353d58c/middleware/favicon/favicon.go#L89-L114","documentation":"Returned by readLimited (favicon.go:103-108) when io.ReadAll fails while reading the favicon from the configured File or FileSystem. favicon.New PANICS with this error at startup (lines 48-49 and 58-59), so it crashes the process during handler construction rather than at request time.","triggerScenarios":"Calling favicon.New(favicon.Config{File: path}) where the file exists (os.Open succeeded) but read returns an I/O error — e.g. disk read fault, NFS hiccup, permission revoked between Open and Read, or a fs.FS reader whose Read returns an error mid-stream.","commonSituations":"Containerized deployments where the favicon file is bind-mounted and the mount becomes unreadable; read permissions differ from open permissions (rare but possible on some filesystems); truncated file.","solutions":["Check read permissions AND readability of the file the process actually opens at startup (not just existence).","If using a custom FileSystem, debug its Open/Read implementation — readLimited consumes whatever it returns.","Switch to favicon.Config{Data: bytes} to remove filesystem dependency entirely.","Run the server under the same UID that owns read access to the file."],"exampleFix":"// before\napp.Use(favicon.New(favicon.Config{File: \"./assets/favicon.ico\"}))\n\n// after — embed the bytes, no filesystem dependency\n//go:embed assets/favicon.ico\nvar faviconBytes []byte\napp.Use(favicon.New(favicon.Config{Data: faviconBytes}))","handlingStrategy":"validation","validationCode":"// pre-flight at startup: ensure the file is readable\nf, err := os.Open(cfg.File)\nif err != nil { log.Fatal(err) }\nbuf := make([]byte, 1)\nif _, err := f.Read(buf); err != nil && err != io.EOF {\n    log.Fatal(err)\n}\n_ = f.Close()","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Run the server under the UID that owns the favicon file.","Prefer favicon.Config{Data: bytes} over File to remove filesystem dependency.","Add a startup healthcheck for the asset path."],"tags":["favicon","filesystem","startup","panic"],"analyzedSha":"9a4c7e57fe0b080a04235d28a4b0d2b4b353d58c","analyzedAt":"2026-08-04T21:44:03.395Z","schemaVersion":2}