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

Gold bugs found
5 of 9
Comments published
6
Comments matching a bug
5
Comments not matching
1
Cost of this PR
$0.070

Published comments (6)

criticalsecurityapp/controllers/uploads_controller.rb:63-70

Shell injection via user-controlled type in tempfile path passed to OptimizedImage.downsize — Shell metacharacters in the user-controlled `type` param end up in the tempfile path that `convert_with` interpolates unescaped into a backtick command, so an API request can run arbitrary commands. Whitelist `type` and escape the path with `Shellwords`.

highbugapp/models/optimized_image.rb:145-151

Duplicate downsize definition drops 5-arg signature, breaking resize_emoji caller — Every emoji upload crashes because `resize_emoji` still calls the five-argument form, raising `ArgumentError` now that the last definition wins. Remove the leftover definition and update `resize_emoji` to pass a dimensions string like `"100x100"`.

highbugapp/controllers/uploads_controller.rb:64-67

Exclude SVG files from ImageMagick downsizing which corrupts them — ImageMagick rewrites the SVG bytes in place, so `Upload.create_for` fails to parse the result and the upload crashes. Exclude SVG from the downsizing branch.

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

Hardcoded 10MB upload limit ignores per-type max size site settings — Sites with `max_image_size_kb` above 10MB wrongly reject valid images, while attachments over a smaller `max_attachment_size_kb` upload fully before the server rejects them. Use the `max_<type>_size_kb` site settings for the client-side limit instead of the hardcoded constant.

highbugapp/controllers/uploads_controller.rb:55-70

URL downloads use hardcoded 10 MB cap, bypassing size limit for non-images — Non-image files fetched by URL up to 10MB are stored as-is, silently overriding the configured site limit for attachments. Use `SiteSetting.max_image_size_kb.kilobytes` as the download cap for non-images, keeping the larger cap only for images.

mediumbugapp/controllers/uploads_controller.rb:64-70

Extension-less temp file path breaks animated GIF detection during downsizing — Multipart tempfiles lack an extension, so the animated-GIF guard in `optimize` never matches and oversized GIFs are flattened to their first frame despite `allow_animated_thumbnails`. Copy the data to a temp file preserving the extension from `filename` before downsizing.

Gold bugs found (5)

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

Gold bugs missed (4)

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