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



commit 057e733eb19cf2f071bd7ada6b79da466ce24fb8
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 |   23 +++++++++++++++++++++++
 2 files changed, 24 insertions(+), 1 deletions(-)
---
diff --git a/src/engine/api/geary-attachment.vala b/src/engine/api/geary-attachment.vala
index 24285e2..25ad46f 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 0c3c919..8127b8d 100644
--- a/test/engine/api/geary-attachment-test.vala
+++ b/test/engine/api/geary-attachment-test.vala
@@ -56,6 +56,8 @@ class Geary.AttachmentTest : 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() {
@@ -236,4 +238,25 @@ class Geary.AttachmentTest : TestCase {
         assert(test.get_safe_file_name.end(async_result()) == RESULT_FILENAME);
     }
 
+    public void get_safe_file_name_with_unknown_content_type()
+        throws Error {
+        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_string(TEST_FILENAME, test.get_safe_file_name.end(async_result()));
+    }
+
 }


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