Amazon Ergo 1.0 · 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 Opus 5.5.

Gold bugs found
4 of 9
Comments published
6
Comments matching a bug
4
Comments not matching
2
Cost of this PR
$1.284

Published comments (6)

highbugapp/models/optimized_image.rb:145-151

resize_emoji calls downsize with the removed five-argument signature — Custom emoji resizing is broken: every `resize_emoji` job enqueued by `Emoji.create_for` raises `ArgumentError` on the five-argument `OptimizedImage.downsize` call. Update `app/jobs/regular/resize_emoji.rb` to pass one geometry string such as `"100x100"`, and remove the dead old `downsize` definition.

highbugapp/controllers/uploads_controller.rb:67

Animated GIF downsizing fails because gifsicle receives a percentage — Large animated GIFs cannot be downsized: `downsize_instructions_animated` passes `80%` to `gifsicle --resize-fit`, which requires `widthxheight` geometry, so all five attempts fail and the oversized original is rejected. Use `FastImage.size` to build pixel geometry for `OptimizedImage.downsize`, falling back to `80%` only when dimensions are unavailable.

highbugapp/controllers/uploads_controller.rb:67

Downsizing the original upload discards animation when thumbnail setting is off — With `SiteSetting.allow_animated_thumbnails` disabled, `downsize_instructions` reads only `#{from}[0]` and overwrites the user's original animated GIF with a single frame, permanently discarding its animation. Pass `allow_animation: true` so preserving the uploaded original does not depend on a thumbnail setting.

highbugapp/controllers/uploads_controller.rb:55

API URL downloads capped at hardcoded 10MB, ignoring max_image_size_kb — Sites with image limits above 10MB lose previously working API URL uploads because `FileHelper.download` uses a hardcoded cap instead of `SiteSetting.max_image_size_kb`. Pass `SiteSetting.max_image_size_kb.kilobytes` as the download limit.

highbugapp/assets/javascripts/discourse/lib/utilities.js:182-185

Upload validation ignores configured per-type size limits — Hardcoding `maxSizeKB` to 10MB lets attachments exceed lower server limits before a full upload is rejected, while blocking valid files on sites configured above 10MB. Restore `Discourse.SiteSettings['max_' + type + '_size_kb']`, applying the 10MB ceiling only when `type === 'image'`.

mediumperformanceapp/controllers/uploads_controller.rb:66-69

Downsize loop keeps retrying after conversion failures — Ignoring a `false` return from `OptimizedImage.downsize` sends corrupt or unsupported images through all five conversion attempts, wasting synchronous API request time without changing `tempfile.size`. Stop the loop when conversion fails and handle the error instead of retrying.

Gold bugs found (4)

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.
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.
mediumThe oversized-image downsize loop in UploadsController#create always uses allow_animated_thumbnails as the animation policy, so with allow_animated_avatars on and allow_animated_thumbnails off an oversized animated GIF avatar is reduced to its first frame before Upload.create_for applies the avatar setting, losing the animation.

Gold bugs missed (5)

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.
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.