DeepSeek V4.1 Flash · Heavy

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

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

The generalist plus 9 specialist lens agents in parallel, then the same verify and dedup steps. 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.192

Published comments (5)

mediumbugapp/controllers/uploads_controller.rb:64-70

Downsize tempfile path lacks extension, collapsing animated GIFs — Without an extension, `file.tempfile.path` fails `optimize`'s `.GIF` check, so `allow_animation` does nothing and every animated GIF is collapsed to one frame. Copy the tempfile to a path carrying the original extension (as `OptimizedImage.create_for` does) before downscaling, then convert back.

mediumperformanceapp/controllers/uploads_controller.rb:55

API upload URL download uses hardcoded 10 MB cap instead of site settings — Hardcoding the ceiling lets any API upload URL, even non-images `FileHelper.is_image?` excludes, force a 10 MB fetch despite a smaller configured limit. Derive the cap from `SiteSetting.max_image_size_kb` and `SiteSetting.max_attachment_size_kb` instead of a constant.

mediumbugapp/models/optimized_image.rb:149-151

New `downsize` definition shadows width/height version and breaks caller — The `downsize` call in `app/jobs/regular/resize_emoji.rb` still passes five positional arguments to the new 3-4 arity, raising `ArgumentError` and leaving emoji un-resized. Update that caller to the `"100x100"` dimension-string form, or keep a width/height-compatible method name.

mediumbugapp/assets/javascripts/discourse/lib/utilities.js:182

Client upload size check hardcodes 10MB instead of using configured site setting — Hardcoding 10 MB desyncs the client from the server, which still enforces `SiteSetting.max_image_size_kb`, so attachments pass client-side then fail server-side. Drive the check from the same `Discourse.SiteSettings['max_' + type + '_size_kb']` setting the server uses.

mediumperformanceapp/controllers/uploads_controller.rb:65-69

Downsizing loop ignores OptimizedImage.downsize failure — When `OptimizedImage.downsize` fails, all five full convert passes still run synchronously, multiplying CPU cost with no size reduction. Break out of the loop when `downsize` returns false.

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.