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)
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.
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.
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.
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 = {})`.
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`
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.