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)
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`.
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"`.
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.
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.
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.
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.