gofiber/fiber · critical
favicon: file size exceeds max bytes %d
Error message
favicon: file size exceeds max bytes %d
What it means
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.
Source
Thrown at middleware/favicon/favicon.go:110
if iconLen > 0 {
c.Set(fiber.HeaderContentLength, iconLenHeader)
c.Set(fiber.HeaderContentType, hType)
c.Set(fiber.HeaderCacheControl, cfg.CacheControl)
return c.Status(fiber.StatusOK).Send(iconData)
}
return c.SendStatus(fiber.StatusNoContent)
}
}
func readLimited(reader io.Reader, maxBytes int64) ([]byte, error) {
limit := maxBytes + 1
data, err := io.ReadAll(io.LimitReader(reader, limit))
if err != nil {
return nil, fmt.Errorf("favicon: read limited: %w", err)
}
if int64(len(data)) > maxBytes {
return nil, fmt.Errorf("favicon: file size exceeds max bytes %d", maxBytes)
}
return data, nil
}
View on GitHub (pinned to 9a4c7e57fe)
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.
Example fix
// before
app.Use(favicon.New()) // default MaxBytes too small for your asset
// after — raise the cap explicitly
app.Use(favicon.New(favicon.Config{
File: "./assets/favicon.ico",
MaxBytes: 1 << 20, // 1 MiB
})) Defensive patterns
Strategy: validation
Validate before calling
// pre-flight: ensure the asset fits before passing to favicon.New
info, err := os.Stat(cfg.File)
if err != nil { log.Fatal(err) }
if info.Size() > int64(cfg.MaxBytes) {
log.Fatalf("favicon %s is %d bytes, max %d", cfg.File, info.Size(), cfg.MaxBytes)
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: Designer delivered a 500KB icon; default MaxBytes too small for the project's chosen asset; build pipeline stopped compressing favicons.
Related errors
- favicon: read limited: %w
- failed to parse client CA certificate from %q
- fiber: service at index %d is nil
- route handler 'fn' cannot be nil
- fiber: Config.RegexHandler return type must support MatchStr
AI-assisted analysis of gofiber/fiber@9a4c7e57fe (2026-08-04).
Data as JSON: /data/errors/a560109d6ecdfc58.json.
Report an issue: GitHub.