{"record":{"id":"1de9bac185b0f1a8","repo":"apache/answer","slug":"image-size-too-large","errorCode":null,"errorMessage":"image size too large","messagePattern":"image size too large","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"pkg/checker/file_type.go","lineNumber":107,"sourceCode":"// registered by transitive dependencies.\nfunc formatSpecificConfigCheck(file io.Reader, ext string, maxImageMegapixel int) error {\n\tvar config image.Config\n\tvar err error\n\tswitch ext {\n\tcase \"jpg\", \"jpeg\":\n\t\tconfig, err = jpeg.DecodeConfig(file)\n\tcase \"png\":\n\t\tconfig, err = png.DecodeConfig(file)\n\tcase \"gif\":\n\t\tconfig, err = gif.DecodeConfig(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 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\n// formatSpecificImageCheck fully decodes the image using a format-specific decoder.\nfunc formatSpecificImageCheck(file io.Reader, ext string, _ int) error {\n\tvar err error\n\tswitch ext {\n\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 {","sourceCodeStart":89,"sourceCodeEnd":125,"githubUrl":"https://github.com/apache/answer/blob/3b9f1370612e690a0b7f230f05e688930db4c6d3/pkg/checker/file_type.go#L89-L125","documentation":"Raised at pkg/checker/file_type.go:107 when imageSizeTooLarge returns true, i.e. the decoded image header's Width*Height exceeds maxImageMegapixel. This is a resource-protection guard preventing memory-exhaustion (image bombing) from huge but valid images; full decode of a giant image would consume large amounts of RAM.","triggerScenarios":"A valid jpg/jpeg/png/gif passes formatSpecificConfigCheck decoding but its pixel dimensions exceed the configured maxImageMegapixel limit (Width*Height > limit).","commonSituations":"Users upload panoramic or high-resolution photos (e.g. 10000x10000), or maxImageMegapixel is configured too low for legitimate use.","solutions":["Resize the image client-side before upload (e.g. canvas/blob downsizing)","Raise the maxImageMegapixel configuration if the limit is too strict","Show the user a clear message that the image resolution exceeds the allowed maximum","Pre-check image dimensions in the browser before upload using Image.naturalWidth/naturalHeight"],"exampleFix":"// before: upload then fail\nupload(file) // -> \"image size too large\"\n// after: client-side pre-check\nconst img = new Image(); img.onload = () => {\n  if (img.naturalWidth * img.naturalHeight > 50_000_000) resizeBeforeUpload(file);\n  else upload(file);\n};","handlingStrategy":"validation","validationCode":"// client-side dimension pre-check\nconst img = new Image();\nimg.onload = () => {\n  if (img.naturalWidth * img.naturalHeight > 50_000_000) reject('image too large');\n};\nimg.src = URL.createObjectURL(file);","typeGuard":"func isImageTooLarge(w, h, maxMP int) bool { return w*h > maxMP }","tryCatchPattern":"if !checker.DecodeAndCheckImageFile(path, maxMP) {\n\treturn fmt.Errorf(\"image dimensions exceed the %d megapixel limit\", maxMP)\n}","preventionTips":["Downscale images client-side before upload","Document the megapixel limit in API/upload docs","Set maxImageMegapixel sensibly for your deployment","Show dimension limit errors clearly to end users"],"tags":["go","image-processing","resource-limits","validation"],"backgroundTag":"image-size-limit-exceeded","analyzedSha":"3b9f1370612e690a0b7f230f05e688930db4c6d3","analyzedAt":"2026-09-05T18:18:39.533Z","contentChangedAt":"2026-09-05T18:18:39.533Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}