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

  1. Raise favicon.Config.MaxBytes to comfortably exceed your asset size.
  2. Compress/resize the favicon — real favicons are well under 10KB.
  3. Use favicon.Config{Data: ...} with a pre-sized byte slice if the asset is dynamic.
  4. 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

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


AI-assisted analysis of gofiber/fiber@9a4c7e57fe (2026-08-04). Data as JSON: /data/errors/a560109d6ecdfc58.json. Report an issue: GitHub.