{"record":{"id":"0f33aca89bcb622b","repo":"instructure/canvas-lms","slug":"source-image-too-large","errorCode":null,"errorMessage":"source image too large","messagePattern":"source image too large","errorType":"exception","errorClass":"ThumbnailError","httpStatus":null,"severity":"error","filePath":"gems/attachment_fu/lib/attachment_fu/processors/mini_magick_processor.rb","lineNumber":51,"sourceCode":"            binary_data = file.is_a?(MiniMagick::Image) ? file : MiniMagick::Image.open(file) if Object.const_defined?(:MiniMagick)\n          rescue\n            # Log the failure to load the image.\n            logger.debug(\"Exception working with image: #{$!}\")\n            binary_data = nil\n          end\n          yield binary_data if block_given? && binary_data\n        end\n      end\n\n      protected\n\n      def process_attachment\n        return unless super\n\n        if image? && !@resized\n          with_image do |img|\n            max_image_size = attachment_options[:thumbnail_max_image_size_pixels]\n            raise ThumbnailError, \"source image too large\" if max_image_size && img[:width] * img[:height] > max_image_size\n\n            resize_image_or_thumbnail! img\n            self.width = img[:width] if respond_to?(:width)\n            self.height = img[:height] if respond_to?(:height)\n            @resized = true\n          end\n        end\n      rescue MiniMagick::Error => e\n        logger.warn(\"MiniMagick processing failed: #{e}\")\n      end\n\n      # Performs the actual resizing operation for a thumbnail\n      def resize_image(img, size)\n        size = size.first if size.is_a?(Array) && size.length == 1\n        img.combine_options do |commands|\n          commands.strip unless attachment_options[:keep_profile]\n\n          commands.limit(\"area\", \"100MB\")","sourceCodeStart":33,"sourceCodeEnd":69,"githubUrl":"https://github.com/instructure/canvas-lms/blob/1c9f0bb8013ed69c4f2efe11fd483025469b7e6c/gems/attachment_fu/lib/attachment_fu/processors/mini_magick_processor.rb#L33-L69","documentation":"attachment_fu's mini_magick processor raises ThumbnailError in process_attachment when the source image's pixel area (width*height) exceeds the configured :thumbnail_max_image_size_pixels limit. The gem refuses to load/process images that could exhaust memory or CPU during resizing. It is a deliberate safety guard, not a corrupt-file error.","triggerScenarios":"Uploading/resizing an image whose width*height exceeds attachment_options[:thumbnail_max_image_size_pixels] while image? is true and the attachment has not yet been resized (@resized is nil). Happens in the mini_magick processing pipeline (with_image block) before resize_image_or_thumbnail! runs.","commonSituations":"Users upload very high-resolution photos (e.g. 50MP) to a Canvas/SitePress-style attachment model with the pixel guard configured; the limit was set for thumbnails but the original attachment goes through the same processor; an account raises upload size limits without adjusting the pixel cap.","solutions":["Resize or re-export the source image below the configured pixel limit before uploading","Raise (or remove) the :thumbnail_max_image_size_pixels option on the attachment model's has_attachment call","Pre-process oversized images with an external tool (ImageMagick mogrify -resize) or a background job that downscales before process_attachment runs","Handle ThumbnailError in the upload flow and surface a friendly message asking users to upload a smaller image"],"exampleFix":"# before\nhas_attachment content_type: :image, max_size: 50.megabytes\n# after\nhas_attachment content_type: :image, max_size: 50.megabytes,\n  thumbnail_max_image_size_pixels: 100_000_000","handlingStrategy":"try-catch","validationCode":"if img[:width] * img[:height] > max_image_size\n  raise UploadTooLarge, 'please upload a smaller image'\nend","typeGuard":"def within_pixel_limit?(width, height, limit)\n  limit.nil? || width * height <= limit\nend","tryCatchPattern":"begin\n  attachment.save\nrescue ThumbnailError => e\n  Rails.logger.warn(e.message)\n  render json: { error: 'Image dimensions exceed the allowed maximum' }, status: :unprocessable_entity\nend","preventionTips":["Validate image dimensions client-side before upload","Configure :thumbnail_max_image_size_pixels consciously and document it","Downscale huge originals in a preprocessing job"],"tags":["image-processing","thumbnail","guard-limit"],"backgroundTag":"file-size-limit-exceeded","analyzedSha":"1c9f0bb8013ed69c4f2efe11fd483025469b7e6c","analyzedAt":"2026-09-15T20:33:18.891Z","contentChangedAt":"2026-09-15T20:33:18.891Z","schemaVersion":2},"datasetVersion":"2026-09-23T02:17:17.105Z"}