[geary/geary-0.12] Fix a crash saving an attachment with unknown content type.



commit 89fe98a800aac4033f94ebb695b020704ee1d1cd
Author: Michael James Gratton <mike vee net>
Date:   Fri Apr 27 12:29:06 2018 +1000

    Fix a crash saving an attachment with unknown content type.
    
    * src/engine/api/geary-attachment.vala (Attachment): Add a null check for
      the extension before using it, add a test case to cover it.

 src/engine/api/geary-attachment.vala       |    2 +-
 test/engine/api/geary-attachment-test.vala |   22 ++++++++++++++++++++++
 2 files changed, 23 insertions(+), 1 deletions(-)
---
diff --git a/src/engine/api/geary-attachment.vala b/src/engine/api/geary-attachment.vala
index d46b66e..4c0a38f 100644
--- a/src/engine/api/geary-attachment.vala
+++ b/src/engine/api/geary-attachment.vala
@@ -155,7 +155,7 @@ public abstract class Geary.Attachment : BaseObject {
                 }
             }
             string? ext = mime_type.get_file_name_extension();
-            if (!file_name.has_suffix(ext)) {
+            if (ext != null && !file_name.has_suffix(ext)) {
                 file_name = file_name + (ext ?? "");
             }
         }
diff --git a/test/engine/api/geary-attachment-test.vala b/test/engine/api/geary-attachment-test.vala
index 5269c02..7121330 100644
--- a/test/engine/api/geary-attachment-test.vala
+++ b/test/engine/api/geary-attachment-test.vala
@@ -56,6 +56,8 @@ class Geary.AttachmentTest : Gee.TestCase {
                  get_safe_file_name_with_default_content_type);
         add_test("get_safe_file_name_with_default_content_type_bad_file_name",
                  get_safe_file_name_with_default_content_type_bad_file_name);
+        add_test("get_safe_file_name_with_unknown_content_type",
+                 get_safe_file_name_with_unknown_content_type);
     }
 
     public override void set_up() {
@@ -235,4 +237,24 @@ class Geary.AttachmentTest : Gee.TestCase {
         assert(test.get_safe_file_name.end(async_result()) == RESULT_FILENAME);
     }
 
+    public void get_safe_file_name_with_unknown_content_type() {
+        const string TEST_FILENAME = "test-filename.unlikely";
+        Attachment test = new TestAttachment(
+            ATTACHMENT_ID,
+            this.default_type,
+            CONTENT_ID,
+            CONTENT_DESC,
+            content_disposition,
+            TEST_FILENAME,
+            File.new_for_path(TEST_FILENAME),
+            742
+        );
+
+        test.get_safe_file_name.begin(null, (obj, ret) => {
+                async_complete(ret);
+            });
+
+        assert(TEST_FILENAME == test.get_safe_file_name.end(async_result()));
+    }
+
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]