Kimi K3.1 Pro · 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 Haiku 5.5.

Gold bugs found
5 of 8
Comments published
5
Comments matching a bug
5
Comments not matching
0
Cost of this PR
$0.885

Published comments (5)

mediumbugapp/models/optimized_image.rb:145-151

The second `downsize` definition replaces the first one in Ruby, leaving only the… — `Jobs::ResizeEmoji#execute` still calls `OptimizedImage.downsize(path, path, 100, 100, opts)` at app/jobs/regular/resize_emoji.rb:14, so every emoji resize now raises `ArgumentError`; remove the obsolete definition and migrate that caller to `"100x100"`, or preserve the old arity.

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

Attachment size validation ignores max_attachment_size_kb — The shared validator now applies a 10 MB limit to attachments as well as images, ignoring `max_attachment_size_kb`. Oversized attachments pass client validation only to be rejected by `UploadValidator`, while sites allowing attachments over 10 MB have valid uploads blocked; keep the new image cap but use `Discourse.SiteSettings.max_attachment_size_kb` when `type` is `attachment`.

mediumbugapp/controllers/uploads_controller.rb:67

Animated GIF downsizing passes an invalid percentage to gifsicle — For API-downloaded GIFs, this `"80%"` value reaches `downsize_instructions_animated`, which emits gifsicle `--resize-fit 80%`, but `--resize-fit` requires `WIDTHxHEIGHT` rather than a percentage. Every conversion attempt fails and the oversized animated GIF remains rejected; handle percentage scaling separately, such as with gifsicle's scale option, or pass valid dimensions.

mediumbugapp/controllers/uploads_controller.rb:67

For normal multipart uploads, `tempfile.path` need not retain the original `.gif` extension, but… — A large animated GIF can therefore use `downsize_instructions` and its first-frame-only input, silently flattening the upload despite `allow_animation`; base the choice on the original filename or an explicit GIF flag.

mediumsecurityapp/controllers/uploads_controller.rb:67

For API URL uploads, attacker-controlled `type` is embedded in the Tempfile prefix on line 55… — A logged-in API caller can place shell metacharacters in `type` and submit an oversized GIF—which previously skipped `fix_image_orientation`—to execute commands, so constrain `type` and invoke the image tools with argument arrays or shell-escaped paths.

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

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