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

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

Published comments (6)

mediumperformanceapp/controllers/uploads_controller.rb:65-69

Every resize retry runs a redundant full ImageOptim pass — Skip optimization during intermediate downsizing passes and run it only once after the final image is produced.

mediumbugapp/controllers/uploads_controller.rb:67

Extensionless upload tempfiles flatten oversized animated GIFs — Direct multipart GIFs use Rack's extensionless `RackMultipart` tempfile, so `OptimizedImage.optimize` does not match `/\.GIF$/i` and selects `downsize_instructions`, whose `#{from}[0]` keeps only the first frame; every oversized animated GIF uploaded through the normal browser path is flattened even with `allow_animated_thumbnails` enabled. Choose the animated converter from the original filename or detected image format rather than the tempfile path.

mediumsecurityapp/controllers/uploads_controller.rb:67

Unescaped tempfile paths enable shell injection during GIF downsizing — For large API-downloaded GIFs, this new call sends a tempfile path containing the unvalidated `type` parameter to `convert_with`, which joins it unquoted into a backtick command; an API user can include shell metacharacters in `type` to execute commands, whereas GIFs previously bypassed the similar orientation command. Shell-escape both paths with `Shellwords.escape` and avoid using raw `type` as a tempfile prefix.

mediumbugapp/models/optimized_image.rb:149-151

Duplicate downsize definition breaks width/height callers — This second `downsize` definition replaces the width/height version above it; Ruby does not overload methods by arity. Existing callers such as `ResizeEmoji` still invoke `OptimizedImage.downsize(path, path, 100, 100, opts)`, which now raises `ArgumentError` because the surviving method accepts only `(from, to, dimensions, opts = {})`.

mediumbugapp/models/optimized_image.rb:149-150

This overload forwards arbitrary geometry strings unchanged, but the new controller caller passes… — For GIFs taking the animated branch, `downsize_instructions_animated` delegates to gifsicle's `--resize-fit`, which requires explicit pixel dimensions and does not accept percentage geometry. The resize therefore fails (and the controller retries the same invalid conversion), leaving large animated GIFs oversized. **Also found in:** - `app/controllers/uploads_controller.rb:67-67`

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

Upload validation ignores per-type file size site settings — The client now validates every image and attachment against a hard-coded 10 MB instead of the corresponding `max_<type>_size_kb` site setting. It therefore rejects files that the configured server limit permits, or accepts files that `Upload.create_for` will reject, and the error message reports this incorrect limit.

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.