apache/answer · warning
unsupported image format: %s
Error message
unsupported image format: %s
What it means
formatSpecificConfigCheck decodes an image's header to enforce a max-megapixel limit, but only supports jpeg, png, and gif. If the file extension is anything else, it returns this error before attempting a decode. It is an explicit allowlist failure, not a decode error.
Source
Thrown at pkg/checker/file_type.go:101
return true
}
// formatSpecificConfigCheck decodes image config using a format-specific decoder
// based on the file extension. This avoids calling image.DecodeConfig() which
// dispatches by magic bytes and can invoke unintended decoders (e.g., TIFF)
// registered by transitive dependencies.
func formatSpecificConfigCheck(file io.Reader, ext string, maxImageMegapixel int) error {
var config image.Config
var err error
switch ext {
case "jpg", "jpeg":
config, err = jpeg.DecodeConfig(file)
case "png":
config, err = png.DecodeConfig(file)
case "gif":
config, err = gif.DecodeConfig(file)
default:
return fmt.Errorf("unsupported image format: %s", ext)
}
if err != nil {
return fmt.Errorf("decode image config error: %v", err)
}
if imageSizeTooLarge(config, maxImageMegapixel) {
return fmt.Errorf("image size too large")
}
return nil
}
// formatSpecificImageCheck fully decodes the image using a format-specific decoder.
func formatSpecificImageCheck(file io.Reader, ext string, _ int) error {
var err error
switch ext {
case "jpg", "jpeg":
_, err = jpeg.Decode(file)
case "png":
_, err = png.Decode(file)View on GitHub (pinned to 3b9f137061)
Solutions
- Convert the image to a supported format (JPEG/PNG) before upload, or use one of the allowed formats.
- If WebP support is needed, add a case "webp" using golang.org/x/image/webp's DecodeConfig.
- Align the allowed-upload-format config with the formats this checker supports.
- Reject early in the UI by filtering the file input accept attribute to supported types.
Example fix
// before
default:
return fmt.Errorf("unsupported image format: %s", ext)
// after
import "golang.org/x/image/webp"
case "webp":
config, err = webp.DecodeConfig(file)
default:
return fmt.Errorf("unsupported image format: %s", ext) Defensive patterns
Strategy: validation
Validate before calling
var allowed = map[string]bool{"jpg": true, "jpeg": true, "png": true, "gif": true}
ext := strings.ToLower(strings.TrimPrefix(filepath.Ext(filename), "."))
if !allowed[ext] {
return fmt.Errorf("format %q not supported; use jpg, png or gif", ext)
} Type guard
func isSupportedImageExt(name string) bool {
switch strings.ToLower(filepath.Ext(name)) {
case ".jpg", ".jpeg", ".png", ".gif":
return true
}
return false
} Try / catch
err := checker.CheckImage(file, maxMegapixel)
if err != nil {
if strings.Contains(err.Error(), "unsupported image format") {
return http.StatusUnsupportedMediaType, "only jpg, png and gif images are supported"
}
return http.StatusBadRequest, err.Error()
} Prevention
- Filter the upload input accept attribute to .jpg,.jpeg,.png,.gif.
- Convert WebP/HEIC/BMP to JPEG or PNG client-side before upload.
- If WebP is required, add a decoder case via golang.org/x/image/webp.
- Keep the checker's allowlist and the upload config's format list in sync.
When it happens
Trigger: Uploading an image whose extension is not jpg/jpeg/png/gif (e.g. webp, bmp, svg, tiff) while it passed the generic file-type check.
Common situations: Modern uploads default to WebP from screenshots/CDN-converted files; users rename non-images to .png or upload HEIC from phones; site config allows a format the checker does not implement.
Related errors
- File validation failed
- validate check exception
- base.request_format_error
- error.password.space_invalid
- decode image config error: %v
AI-assisted analysis of apache/answer@3b9f137061 (2026-09-05).
Data as JSON: /api/errors/fc7f058a32970d4f.
Report an issue: GitHub.