Repository navigation
fix(ui): sample composer image preview to avoid Canvas draw crash - #1210
Merged
Merged
Conversation
The composer preview decoded the selected image bytes at full resolution. An ORIGINAL-preset send of an 8160x6144 photo produced a 200,540,160-byte bitmap (8160*6144*4), which the hardware canvas refuses to draw above 100MB, crashing with "Canvas: trying to draw too large(...) bitmap" when attaching large images. Decode the preview bounds-first with power-of-two sampling via the new ImageUtils.decodeSampledBitmap (1024px cap), matching the message-bubble path. The send pipeline is unchanged: ORIGINAL still ships the full-resolution image; only the preview is sampled. Fixes #1209 Fixes COLUMBA-EC
Contributor
[Low impact] The PR appears safe to merge; no actionable new issue was found. SummaryThe PR samples composer image previews without changing the image sent.
No actionable new issues were found. Tests were not run during this review. Reviews (3) · Last reviewed commit: "test(ui): pin that preset re-encoding st..." · Reviewed by Greptile |
The privacy guarantee (camera GPS/device info never leaves the device via an image message) comes from decode->re-encode, not from the WebP container: the preset path emits JPEG, yet Bitmap.compress writes a fresh file from raw pixels. Stamp GPS + rotate-90 EXIF onto a JPEG, run the ORIGINAL preset, and assert the output carries no GPS, claims no rotation, and has the rotation baked into pixels.
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Owner
Author
|
@greptile review |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Closes #1209. Sending a large image at Original quality crashed with
Canvas: trying to draw too large(200540160 bytes) bitmap.The composer preview decoded the selected image bytes at full resolution (
MessagingScreenBitmapFactory.decodeByteArray). The ORIGINAL preset caps at 8192px, so the reporter's 8160×6144 photo passed through the pipeline unscaled; decoding it for the 80.dp preview allocated an 8160×6144×4 = 200,540,160-byte bitmap, which the hardware canvas refuses to draw above its 100MB limit (RecordingCanvas.MAX_BITMAP_SIZE).Fix
Decode the preview bounds-first with power-of-two sampling via a new
ImageUtils.decodeSampledBitmap(bytes, maxDimensionPx)(1024px cap) — the same strategy the message-bubble path already uses. Every live draw path now samples (preview, bubble, Micron images, Coil GIFs/fullscreen).The send pipeline is unchanged: ORIGINAL still ships the full-resolution image. Only the preview is sampled, so image quality on the wire is preserved.
Metadata stripping still holds at ORIGINAL
The EXIF/GPS-stripping guarantee comes from decode → re-encode, not from the WebP container:
loadBitmapdecodes to raw pixels (baking EXIF orientation in) andBitmap.compresswrites a fresh file, so source APP1 metadata (GPS, device model) never survives — even though the preset path emits JPEG rather than WebP. A new regression test pins this: stamped GPS + rotate-90 input → ORIGINAL output has no GPS, claims no rotation, and carries the rotation in pixels.Tests
ImageUtilsRobolectricTest(Robolectric, realcompressImageWithPresetpipeline on a synthetic 8160×6144 JPEG):ORIGINAL preset preview fits hardware canvas limit— the red repro (200,540,160 bytes) now ≤ 100MBORIGINAL preset preserves source dimensions on the wire— output stays 8160×6144 (guards against shrinking the send)ORIGINAL preset strips EXIF metadata from the sent image— privacy invariant: GPS never rides along at ORIGINAL qualityHIGH preset preview fits hardware canvas limit— controldecodeSampledBitmap samples large images below twice the target dimensionImageUtilsRobolectricTest38/38,MessagingScreenTestgreen,:app:detektclean.Fixes COLUMBA-EC