{"id":"a560109d6ecdfc58","repo":"gofiber/fiber","slug":"favicon-file-size-exceeds-max-bytes-d","errorCode":null,"errorMessage":"favicon: file size exceeds max bytes %d","messagePattern":"favicon: file size exceeds max bytes (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"middleware/favicon/favicon.go","lineNumber":110,"sourceCode":"\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":92,"sourceCodeEnd":114,"githubUrl":"https://github.com/gofiber/fiber/blob/9a4c7e57fe0b080a04235d28a4b0d2b4b353d58c/middleware/favicon/favicon.go#L92-L114","documentation":"Returned by readLimited (favicon.go:109-111) when the favicon file is larger than the configured MaxBytes limit. Like [164], favicon.New panics with this at startup, failing process boot. readLimited reads MaxBytes+1 and flags any file that fills that extra byte.","triggerScenarios":"Calling favicon.New with a File whose size in bytes exceeds cfg.MaxBytes (default is bounded — check ConfigDefault). Commonly: shipping a multi-resolution .ico, a PNG misnamed .ico, or an uncompressed icon bundle.","commonSituations":"Designer delivered a 500KB icon; default MaxBytes too small for the project's chosen asset; build pipeline stopped compressing favicons.","solutions":["Raise favicon.Config.MaxBytes to comfortably exceed your asset size.","Compress/resize the favicon — real favicons are well under 10KB.","Use favicon.Config{Data: ...} with a pre-sized byte slice if the asset is dynamic.","Move the oversized asset out of the File path and serve it via a static handler instead."],"exampleFix":"// before\napp.Use(favicon.New()) // default MaxBytes too small for your asset\n\n// after — raise the cap explicitly\napp.Use(favicon.New(favicon.Config{\n    File:     \"./assets/favicon.ico\",\n    MaxBytes: 1 << 20, // 1 MiB\n}))","handlingStrategy":"validation","validationCode":"// pre-flight: ensure the asset fits before passing to favicon.New\ninfo, err := os.Stat(cfg.File)\nif err != nil { log.Fatal(err) }\nif info.Size() > int64(cfg.MaxBytes) {\n    log.Fatalf(\"favicon %s is %d bytes, max %d\", cfg.File, info.Size(), cfg.MaxBytes)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Compress favicons as part of the build pipeline.","Set MaxBytes explicitly to a value your assets can never exceed.","Use Data instead of File when the asset size varies."],"tags":["favicon","config","startup","panic","filesize"],"analyzedSha":"9a4c7e57fe0b080a04235d28a4b0d2b4b353d58c","analyzedAt":"2026-08-04T21:44:03.395Z","schemaVersion":2}