Amazon Ergo 1.0 · 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
4 of 9
Comments published
5
Comments matching a bug
4
Comments not matching
1
Cost of this PR
$2.304

Published comments (5)

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

Upload validation ignores configured size limits — The hardcoded `10 * 1024` cap ignores `Discourse.SiteSettings['max_' + type + '_size_kb']`, blocking sites that allow larger files and letting files over smaller configured limits upload before server rejection; `test/javascripts/lib/utilities-test.js.es6` also fails. Restore the site-setting lookup here and in the 413 handler.

highbugapp/controllers/uploads_controller.rb:67

Animated GIF resizing passes percentage geometry to gifsicle — With `allow_animated_thumbnails` enabled, large animated GIFs cannot be uploaded: `downsize_instructions_animated` passes `80%` to `gifsicle --resize-fit`, which expects pixel geometry, so the loop exhausts its attempts and `Validators::UploadValidator` rejects the oversized file. Use computed pixel dimensions or `--scale`.

highbugapp/models/optimized_image.rb:149-150

downsize no longer accepts width and height arguments — Custom emoji images are never resized: `app/jobs/regular/resize_emoji.rb` still calls `OptimizedImage.downsize` with five arguments, raising `ArgumentError` and accumulating failed jobs. Pass a dimensions string such as `100x100` or preserve the old signature.

mediumbugapp/controllers/uploads_controller.rb:64-69

Large animated GIFs are flattened when downsized — Animated GIFs over `max_image_size_kb` lose all but their first frame because `OptimizedImage.downsize` receives an extensionless Rack tempfile path, so `optimize` misses `downsize_instructions_animated`. Pass the original filename/extension or detect animation from file content so the animated branch runs.

mediumbugapp/controllers/uploads_controller.rb:64-70

Downsize loop can still upload images over the size limit — Five `80%` passes can leave an image above `max_image_size_kb`, and ignoring `OptimizedImage.downsize` failures wastes attempts before `Upload.create_for` stores an oversized file. Check `tempfile.size` after the loop and return an error or use a fallback; stop retrying when `OptimizedImage.downsize` returns false.

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

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.