gofiber/fiber · critical

favicon: file size exceeds max bytes

Error message

favicon: file size exceeds max bytes %d

What it means

Returned by favicon.readLimited when the favicon file exceeds Config.MaxBytes. The function reads MaxBytes+1 bytes; if it reads more than MaxBytes, the file is too large and (like error 165) New() panics with this message at middleware construction. Default MaxBytes is small to keep favicons lightweight.

Solutions

  1. Use a smaller favicon — strip oversized icon variants to fit MaxBytes.
  2. Raise Config.MaxBytes to a value that comfortably covers the file (e.g. 1<<20).
  3. If the file is intentionally large, prefer serving it via a static handler instead of the favicon middleware.
  4. Check the file size at deploy time: `stat -c%s cfg.File`.

Example fix

// before
app.Use(favicon.New())
// after
app.Use(favicon.New(favicon.Config{
    File:     "./assets/favicon.ico",
    MaxBytes: 1 << 20, // 1 MiB
}))
Defensive patterns

Strategy: validation

Validate before calling

if fi, err := os.Stat(cfg.File); err == nil && fi.Size() > int64(cfg.MaxBytes) { log.Fatalf("favicon too large: %d > %d", fi.Size(), cfg.MaxBytes) }

Prevention

When it happens

Trigger: favicon.New configured with a File whose size is greater than Config.MaxBytes. Triggers at startup during the one-shot read in New(), causing the process to panic before serving traffic.

Common situations: Dropping a high-resolution .ico/.png as favicon.ico, leaving the default small MaxBytes, or pointing File at a multi-resolution .ico that contains 32/64/128px variants and exceeds the cap.

Related errors


AI-assisted analysis of gofiber/fiber@a105acad6c (2026-08-11). Data as JSON: /api/errors/a560109d6ecdfc58. Report an issue: GitHub.

Appendix: 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 a105acad6c)