DeepSeek V4.1 Flash · Balanced

feature-automatically-downsize-large-images-discourse-cursor

Discourse · Ruby · S · 30–99 lines · 3 files

The normal review, with one generalist agent. Judge: Claude Haiku 5.5.

Gold bugs found
3 of 8
Comments published
5
Comments matching a bug
3
Comments not matching
2
Cost of this PR
$0.133

Published comments (5)

mediumbugapp/models/optimized_image.rb:145-151

Duplicate OptimizedImage.downsize breaks 5-argument emoji call — The 4-argument `downsize` at line 149 shadows the 5-argument version, so `Jobs::ResizeEmoji` calling it with 5 arguments will raise `ArgumentError` and custom emoji stop being downsized. Remove the dead definition and convert the emoji caller to a single `"100x100"` argument.

mediumbugapp/controllers/uploads_controller.rb:67

Animated GIF form uploads are downscaled to a static frame — `allow_animation` never matches because `downsize_instructions` tests the extensionless tempfile path, so animated GIFs collapse to a static frame. Pass the original `filename` into the downsize call as `app/models/upload.rb` already does.

mediumbugapp/assets/javascripts/discourse/lib/utilities.js:179-185

Upload size validation ignores admin-configured max size settings — Hardcoding 10MB drops the `max_<type>_size_kb` lookup, so client-side validation no longer honors admin limits and `utilities-test.js.es6:52` can no longer trigger `file_too_large`. Keep the `Discourse.SiteSettings['max_' + type + '_size_kb']` lookup.

mediumbugapp/controllers/uploads_controller.rb:64-70

Oversized images not rejected after failed downsize attempts — A file still oversized after 5 passes is only rejected later by `Validators::UploadValidator#maximum_image_file_size`, wasting up to 5 conversions before the user sees an error. Derive the scale from `tempfile.size / SiteSetting.max_image_size_kb.kilobytes` and abort explicitly if it stays too large.

mediumperformanceapp/controllers/uploads_controller.rb:65-69

Oversized uploads run up to five ImageMagick passes — Each oversized upload runs up to five full ImageMagick cycles plus `ImageOptim` in `convert_with` (app/models/optimized_image.rb), multiplying CPU cost for large files. Resize once with a factor from the size ratio rather than iterating relative 80% steps.

Gold bugs found (3)

highdownsize is defined twice in OptimizedImage; the new (from, to, dimensions, opts) version overrides the (max_width, max_height) one, so existing callers such as ResizeEmoji that pass width and height now raise ArgumentError.
highThe client-side upload size check hardcodes 10 MB instead of the per-type max_<type>_size_kb setting, so attachment limits diverge from the server: larger allowed attachments are blocked and smaller limits are only enforced server-side.
mediumAuto-downsizing passes the upload tempfile path, which lacks a .gif extension, so the animated branch is never chosen and convert keeps only the first frame, flattening oversized animated GIFs.

Gold bugs missed (5)

highThe upload downsizing passes a percentage ('80%') as dimensions, but for animated GIFs the gifsicle path uses --resize-fit, which expects WxH geometry, so downsizing silently fails.
highClaims the downsize loop checking tempfile.size may never terminate because of a stale cached size, causing infinite loops.
highOversized SVG uploads go through the new ImageMagick downsize loop because SVG counts as an image, so the vector file is rasterized or corrupted in place before Upload.create_for parses it as SVG.
criticalThe upload tempfile path, which for API URL uploads embeds the request-controlled type param, is now passed to OptimizedImage.downsize and run unescaped in a shell via backticks, allowing command injection through type.
mediumThe 413 upload error message states a hard-coded 10 MB maximum that may not match the limit the server or web server actually enforces.