GLM-5.3 · 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
- 4 of 8
- Comments published
- 6
- Comments matching a bug
- 4
- Comments not matching
- 2
- Cost of this PR
- $2.730
Published comments (6)
Shell injection: unsanitized type param reaches shell via tempfile path — An API request with shell metacharacters in the unsanitized `type` param achieves arbitrary command execution: the `FileHelper.download` tempfile basename embeds `type` and reaches `convert_with`'s interpolated shell string via `OptimizedImage.downsize`. Whitelist `type` and use array-form process spawning.
Duplicate downsize definition shadows the 5-arg version and breaks ResizeEmoji — Custom emoji are never resized: `Jobs::ResizeEmoji`'s 5-argument call raises `ArgumentError` against the surviving 4-parameter `downsize`. Delete the duplicate definition and pass a dimensions string from `resize_emoji.rb`.
Hardcoded 10MB limit ignores per-type site settings for file size validation — The hardcoded `maxSizeKB` lets attachments above `max_attachment_size_kb` pass client validation only to fail server-side in `Validators::UploadValidator#maximum_file_size`, and blocks valid uploads when admins raise limits past 10MB. Read `Discourse.SiteSettings['max_' + type + '_size_kb']` instead. **Also found in:** - `app/assets/javascripts/discourse/lib/utilities.js:244-248`
Downsize retry loop ignores failures and wastes CPU on intermediate ImageOptim passes — Large uploads now spend tens of seconds of sequential CPU: each iteration's `ImageOptim` pass is overwritten by the next `convert`, and a failed `downsize` still burns all 5 attempts. Break on failure and optimize only once, after the loop.
Browser-uploaded animated GIFs lose animation when auto-downsized — Rack multipart tempfiles lack the `.gif` extension, so `optimize`'s animation check never matches and browser-uploaded animated GIFs are flattened to a static first frame despite `allow_animation`. Base the animated decision on the upload filename rather than the tempfile path.
Downsize loop capped at 5 iterations may not reach the allowed image size — Five 80% passes leave a 10MB image near 3.3MB when `max_image_size_kb` is 1024, so `Upload.create_for` still rejects it despite the comment's promise. Loop until under the limit, breaking when the size stops shrinking.