{"record":{"id":"af859640563335e3","repo":"apache/answer","slug":"decode-webp-image-config-error-v","errorCode":null,"errorMessage":"decode webp image config error: %v","messagePattern":"decode webp image config error: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/checker/file_type.go","lineNumber":134,"sourceCode":"\tcase \"jpg\", \"jpeg\":\n\t\t_, err = jpeg.Decode(file)\n\tcase \"png\":\n\t\t_, err = png.Decode(file)\n\tcase \"gif\":\n\t\t_, err = gif.Decode(file)\n\tdefault:\n\t\treturn fmt.Errorf(\"unsupported image format: %s\", ext)\n\t}\n\tif err != nil {\n\t\treturn fmt.Errorf(\"decode image error: %v\", err)\n\t}\n\treturn nil\n}\n\nfunc webpImageConfigCheck(file io.Reader, _ string, maxImageMegapixel int) error {\n\tconfig, err := webp.DecodeConfig(file)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"decode webp image config error: %v\", err)\n\t}\n\tif imageSizeTooLarge(config, maxImageMegapixel) {\n\t\treturn fmt.Errorf(\"image size too large\")\n\t}\n\treturn nil\n}\n\nfunc webpImageCheck(file io.Reader, _ string, _ int) error {\n\t_, err := webp.Decode(file)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"decode webp image error: %v\", err)\n\t}\n\treturn nil\n}\n\nfunc imageSizeTooLarge(config image.Config, maxImageMegapixel int) bool {\n\treturn config.Width*config.Height > maxImageMegapixel\n}","sourceCodeStart":116,"sourceCodeEnd":152,"githubUrl":"https://github.com/apache/answer/blob/3b9f1370612e690a0b7f230f05e688930db4c6d3/pkg/checker/file_type.go#L116-L152","documentation":"webpImageConfigCheck wraps errors from golang.org/x/image/webp's DecodeConfig at pkg/checker/file_type.go:134. Thrown when a file with the .webp extension cannot have its VP8/VP8L/VP8X header parsed as WebP.","triggerScenarios":"A .webp file fails webp.DecodeConfig: not actually WebP content (renamed JPEG/PNG), truncated header, or a WebP variant unsupported by x/image/webp (e.g. extended-format features the library rejects).","commonSituations":"Users rename other formats to .webp; animated WebP or alpha-channel VP8X files produced by modern encoders hit limitations of the older x/image/webp decoder.","solutions":["Verify the file is real WebP (RIFF....WEBP magic bytes) before upload","Re-encode the image as lossy/lossless WebP without extended features (ffmpeg -c:v libwebp)","Upgrade golang.org/x/image to the latest version for newer WebP feature support","Fall back to another format (PNG/JPEG) if the WebP variant is unsupported"],"exampleFix":"// before: trust extension\nif ext == \"webp\" { /* decode */ }\n// after: check magic bytes\nhead := make([]byte, 12)\nio.ReadFull(f, head)\nif string(head[0:4]) != \"RIFF\" || string(head[8:12]) != \"WEBP\" { return errors.New(\"not webp\") }","handlingStrategy":"validation","validationCode":"head := make([]byte, 12)\nio.ReadFull(f, head)\nif string(head[0:4]) != \"RIFF\" || string(head[8:12]) != \"WEBP\" {\n\treturn errors.New(\"file is not WebP despite extension\")\n}","typeGuard":"func isWebPDecodeErr(err error) bool { return err != nil && strings.HasPrefix(err.Error(), \"decode webp image config error\") }","tryCatchPattern":"if err := webpImageConfigCheck(f, \"webp\", maxMP); err != nil {\n\treturn fmt.Errorf(\"webp rejected: %w\", err)\n}","preventionTips":["Check RIFF....WEBP magic bytes before trusting the .webp extension","Keep golang.org/x/image up to date","Re-encode edge-case WebP (animated/extended) with cwebp before upload","Offer PNG/JPEG fallback formats"],"tags":["go","webp","image-decoding","file-upload"],"backgroundTag":"image-decode-failed","analyzedSha":"3b9f1370612e690a0b7f230f05e688930db4c6d3","analyzedAt":"2026-09-05T18:18:39.533Z","contentChangedAt":"2026-09-05T18:18:39.533Z","schemaVersion":2},"datasetVersion":"2026-09-12T22:17:10.623Z"}