Bound decoded image size so a received thumbnail cannot OOM the app #1231
All Vouch review confidence checks passed
Residual risk 0.27 = Change Risk (0.48) × (1 − Review Confidence (0.43)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.48 · 544 lines diff across 6 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.377
Shallow Review Depth
shallow_review_depth
0.344
Real PR Conversation Timeline
1 comments
"Review active on #1231"
general
weight: 0.35
greptile-apps[bot]
What
A received message's inline
jpeg_thumbnailis fully controlled by the sender and is drawn the moment the chat opens, through egui_extras'ImageCrateLoader. That loader decodes with no size limit: it hands the bytes straight toimage::DynamicImage::from_decoder, which does not enforce even theimagecrate's own default 512 MiB allocation ceiling (that ceiling is only applied byImageReader::decode, a path the loader never takes). egui'smax_texture_sideclamp happens only after theColorImageis already fully allocated, so it does not help.Result: a thumbnail of a few dozen bytes that declares huge dimensions (e.g. a PNG header saying 50000x50000) makes the loader reserve ~10 GB and the process is killed, with no action from the reader beyond opening the chat. That is a zero-click denial of service. The downloaded full photo, shown as a tile through the same loader, has the same exposure (a
<= 64 MiBfile declaring absurd dimensions).The project already knows the right guard (
image::Limitsinanimation.rs's poster decode and inlink_preview.rs), but the received-thumbnail / displayed-image path through egui never applied it.Reproduce (offline, no live account)
Feed a crafted PNG whose IHDR declares 50000x50000 (a valid header, a few bytes) to the same decode the loader uses (
DynamicImage::from_decoder): it reserves gigabytes rather than erroring. Before this change, drawing such a thumbnail aborts the app; after it, the thumbnail is rejected and the rest of the chat renders.Fix
A small size-bounded image loader (
src/bounded_image.rs) installed on top of egui_extras' loaders. egui tries image loaders in reverse insertion order, so the last one added wins the still-raster path. It decodes throughimage::Limits, rejecting an oversized header or allocation before any buffer is reserved, exactly asanimation.rsalready does for posters:bytes://) get a tight bound (4096 px per side, 64 MiB), matchinganimation.rs. This is the pure zero-click vector.file://) get theimagecrate's own default 512 MiB ceiling (the one this path skipped) plus a generous per-side cap that also blocks an absurdly thin, long image that would slip under the allocation ceiling..gif). Only genuine GIF, WebP and SVG are deferred to egui_extras' ownGifLoader/WebPLoader/SvgLoader, which keep rendering those unchanged.Threading and caching mirror
ImageCrateLoader, so behaviour is identical apart from the limit.Known limitation
GIF, WebP and SVG still go through egui_extras' own loaders, which have no limit of their own, so a pixel bomb of those formats drawn via egui stays as exposed as before (no regression). In practice ZapFast draws animated GIF/WebP through
animation.rs(already bounded), so only still JPEG/PNG reach this path. Bounding the animated loaders too can be a follow-up.Tests
src/bounded_image.rsadds:Platform coverage
Built and tested on Linux (
fmt,clippywith and without--all-features,testx2,docall pass). The code is platform-independent (nocfgbranches); Windows and macOS compile the same path.<!-- This is an auto-generated comment: release notes by coderabbit.ai -->
<!-- coderabbit-ai-generated:v1 -->
Summary by CodeRabbit
New Features
Image loading now applies size and file limits based on the image source, helping prevent oversized images from consuming excessive resources.
GIF, WebP, and SVG images continue to use their existing support, while other image types are decoded with bounded limits.
Images that exceed decoding limits or cannot be decoded now show a loading error.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->