Repository navigation
Conversation
When pastedImageData receives bytes that do not match BMP, JPEG, PNG, GIF, or WebP, attempt to decode them to PNG with convertToPng instead of saving the raw bytes with a .png suffix. Drop the pasted item if conversion returns null or throws.
|
AI review done for Quality: Needs fixes before merge. Four send-path comparisons confirmed that images accepted by the previous revision now fail before upload.
|
| if (max(width, height) > _kMaxDimension) { | ||
| image = switch (width / height) { | ||
| < 1 / 3 => bakeOrientation(image), | ||
| > 1 => copyResize(image, width: _kMaxDimension), |
There was a problem hiding this comment.
A 1×5000 PNG with EXIF orientation 6 used to upload with compression enabled. The new width-only resize treats it as 5000×1 and rounds the target height to zero, so the encoder throws Cannot encode an empty image. Compute both target dimensions from the oriented size and clamp each to at least one pixel.
| if (type == 'IEND' && end != start + 12) throw Exception('compress failed'); | ||
| if (end > bytes.length) { | ||
| if (type == 'IEND') break; | ||
| throw Exception('compress failed'); |
There was a problem hiding this comment.
This aborts uncompressed sends when only trailing metadata is truncated. A PNG with complete IDAT data and a truncated final tEXt chunk decoded in Flutter and uploaded after sanitization on 4a567ac. Recover this case by dropping the damaged tail and writing a fresh IEND after verifying the retained pixels decode.
| if (copiedUntil == 0) return bytes; | ||
| clean.add(Uint8List.sublistView(bytes, copiedUntil)); | ||
| if (orientation != null) { | ||
| if (flagsOffset == null) throw Exception('compress failed'); |
There was a problem hiding this comment.
A WebP with a valid image bitstream and an appended EXIF chunk now fails to send if it lacks VP8X. Flutter decoded the fixture, and 4a567ac uploaded it with orientation-only EXIF. Rebuild VP8X from the bitstream when needed, or restore the sanitized re-encode fallback for this case.
|
|
||
| // A readable WebP header does not prove that the frame bitstreams decode. | ||
| try { | ||
| final info = decoder.startDecode(output); |
There was a problem hiding this comment.
The Dart decode check rejects some files Flutter can display. A 16×8 single-frame animated WebP with XMP and a nonzero reserved VP8X byte decoded in Flutter and uploaded on 4a567ac. The rewritten file now fails startDecode and aborts before upload. Use Flutter's decoder to validate the sanitized output so sending and display accept the same files.
Summary
Follow-up to #2159.
send image message compressed compressImage - re-encode, source EXIF copied (GPS included) + re-encode, keep only EXIF orientation uncompressed - upload original bytes (GPS included) + stripImageMetadata (off the UI isolate), pixels unchanged: + JPEG: keep JFIF, ICC, Adobe and image segments; EXIF -> orientation only; drop XMP, IPTC, other APPn + PNG: EXIF -> orientation only; drop XMP and raw-profile text chunks; keep iCCP + WebP: EXIF -> orientation only; drop XMP; fix VP8X flags + unreadable EXIF -> dropped; malformed file with metadata -> re-encoded + a forward whose bytes change uploads again paste image data (pastedImageData) JPEG / PNG / GIF / WebP -> keep bytes and extension (unchanged) BMP -> unchanged - anything else -> saved as .png + anything else -> decode to PNG, or paste nothing if decoding failsPasting, picking, dropping and URL images all go through
compressImageorsendImageMessage, so one change covers each source. The Android and iOS clients re-encode images before upload, so their output also has no source GPS.Evidence
test/utils/image_test.dart: a generated JPEG with GPS EXIF and orientation.test/account/send_message_helper_test.dartandtest/utils/image_test.dart: uncompressed JPEG, PNG and WebP with GPS EXIF, XMP and IPTC.RangeErrorand the send fails.test/utils/clipboard_test.dart:.png; a decodable TIFF and a throwing decoder are not handled.flutter test test/utils/ test/account/: 240 passed, 4 skipped.dart analyze --fatal-infos lib test: no issues.Merge Danger
Door: two-way
Blast Radius: sent images.
.png.