[geary] Don't crash when attempting to display a 0-sized inline image.
- From: Michael Gratton <mjog src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [geary] Don't crash when attempting to display a 0-sized inline image.
- Date: Fri, 18 Nov 2016 03:01:40 +0000 (UTC)
commit 7ba13e934d13eac984f34541ebd040d40bf550df
Author: Michael James Gratton <mike vee net>
Date: Fri Nov 18 11:44:23 2016 +1100
Don't crash when attempting to display a 0-sized inline image.
* src/client/conversation-viewer/conversation-message.vala
(ConversationMessage::clean_html_markup): Check the image buffer
actually has some bytes before processing it.
.../conversation-viewer/conversation-message.vala | 50 ++++++++++---------
1 files changed, 26 insertions(+), 24 deletions(-)
---
diff --git a/src/client/conversation-viewer/conversation-message.vala
b/src/client/conversation-viewer/conversation-message.vala
index 229c52d..bd3f545 100644
--- a/src/client/conversation-viewer/conversation-message.vala
+++ b/src/client/conversation-viewer/conversation-message.vala
@@ -1023,30 +1023,32 @@ public class ConversationMessage : Gtk.Grid {
if (!replaced_content_ids.contains(content_id)) {
string? filename = message.get_content_filename_by_mime_id(content_id);
Geary.Memory.Buffer image_content = message.get_content_by_mime_id(content_id);
- Geary.Memory.UnownedBytesBuffer? unowned_buffer =
- image_content as Geary.Memory.UnownedBytesBuffer;
-
- // Get the content type.
- string guess;
- if (unowned_buffer != null)
- guess = ContentType.guess(null, unowned_buffer.to_unowned_uint8_array(), null);
- else
- guess = ContentType.guess(null, image_content.get_uint8_array(), null);
-
- string mimetype = ContentType.get_mime_type(guess);
-
- // Replace the SRC to a data URI, the class to a known label for the popup menu,
- // and the ALT to its filename, if supplied
- img.remove_attribute("src"); // Work around a WebKitGTK+ crash. Bug 764152
- img.set_attribute("src", Util.DOM.assemble_data_uri(mimetype, image_content));
- img.class_list.add(DATA_IMAGE_CLASS);
- if (!Geary.String.is_empty(filename))
- img.set_attribute("alt", filename);
-
- // stash here so inlined image isn't listed as attachment (esp. if it has no
- // Content-Disposition)
- inlined_content_ids.add(content_id);
- attachment_displayed_inline(content_id);
+ if (image_content.size > 0) {
+ Geary.Memory.UnownedBytesBuffer? unowned_buffer =
+ image_content as Geary.Memory.UnownedBytesBuffer;
+
+ // Get the content type.
+ string guess;
+ if (unowned_buffer != null)
+ guess = ContentType.guess(null, unowned_buffer.to_unowned_uint8_array(), null);
+ else
+ guess = ContentType.guess(null, image_content.get_uint8_array(), null);
+
+ string mimetype = ContentType.get_mime_type(guess);
+
+ // Replace the SRC to a data URI, the class to a known label for the popup menu,
+ // and the ALT to its filename, if supplied
+ img.remove_attribute("src"); // Work around a WebKitGTK+ crash. Bug 764152
+ img.set_attribute("src", Util.DOM.assemble_data_uri(mimetype, image_content));
+ img.class_list.add(DATA_IMAGE_CLASS);
+ if (!Geary.String.is_empty(filename))
+ img.set_attribute("alt", filename);
+
+ // stash here so inlined image isn't listed as attachment (esp. if it has no
+ // Content-Disposition)
+ inlined_content_ids.add(content_id);
+ attachment_displayed_inline(content_id);
+ }
} else {
// replaced by data: URI, remove this tag and let the inserted one shine through
img.parent_element.remove_child(img);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]