GLM-5.3 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 Opus 5.5.

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

Published comments (5)

highbugapp/controllers/uploads_controller.rb:66-69

Over-limit image stored when OptimizedImage.downsize fails or makes no progress — When the convert subprocess fails, `tempfile.size` never shrinks, so the command runs five times and the oversized image is still stored since `Upload.create_for` never revalidates the limit. Check the `OptimizedImage.downsize` return value and fail the upload when no progress is made.

highbugapp/models/optimized_image.rb:149-151

4-arg downsize overrides 5-arg version, breaking ResizeEmoji caller — `app/jobs/regular/resize_emoji.rb` still calls the old 5-argument form, so every emoji resize now raises an `ArgumentError` and the background job fails. Make `downsize` accept both signatures or update that caller.

highbugapp/controllers/uploads_controller.rb:64-69

Animated GIFs flattened by downsize since tempfile path lacks file extension — The extensionless Rack tempfile path means `OptimizedImage.optimize` never takes the animated branch and its `convert` keeps only the first frame, silently flattening oversized GIFs. Copy the upload into a `Tempfile` carrying the filename's extension before downsizing.

mediumperformanceapp/controllers/uploads_controller.rb:65-69

Downsize loop runs all 5 attempts even when convert fails or file shrinks — A failed convert leaves the file unchanged, so all five synchronous `OptimizedImage.downsize` calls still execute in the request thread and can pin workers or exhaust CPU under concurrent uploads. Break out of the loop when `tempfile.size` stops shrinking.

mediumbugapp/assets/javascripts/discourse/lib/utilities.js:181-183

Hardcoded 10MB client limit ignores per-type site settings — On sites with a smaller configured limit, non-image files under 10MB pass client validation, consume upload bandwidth, and are then rejected by the server citing a different limit. Keep reading `Discourse.SiteSettings['max_' + type + '_size_kb']` instead of hardcoding it.

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 (6)

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