[meld] Handle recent-file reading of malformed files (closes bgo#690472)



commit 2342abca791dc43c3acddedffa75eba14ad23acd
Author: Kai Willadsen <kai willadsen gmail com>
Date:   Fri Dec 21 05:59:36 2012 +1000

    Handle recent-file reading of malformed files (closes bgo#690472)
    
    While it's not entirely clear how this could happen, some non-meldcmp
    files can end up in Meld's recent file list. While we check for
    configparser files that don't match the layout we expect, we don't
    check for recent files that aren't even configparser files. This commit
    adds such a check.
    
    It's entirely possible that the cause of this problem is simply
    development changes, but the error handling is a good idea anyway.

 meld/recent.py |   13 +++++++------
 1 files changed, 7 insertions(+), 6 deletions(-)
---
diff --git a/meld/recent.py b/meld/recent.py
index 48510df..7cc18e9 100644
--- a/meld/recent.py
+++ b/meld/recent.py
@@ -118,12 +118,13 @@ class RecentFiles(object):
         if not gio_file.query_exists() or not path:
             raise IOError("File does not exist")
 
-        config = ConfigParser.RawConfigParser()
-        config.read(path)
-
-        if not (config.has_section("Comparison") and
-                config.has_option("Comparison", "type") and
-                config.has_option("Comparison", "paths")):
+        try:
+            config = ConfigParser.RawConfigParser()
+            config.read(path)
+            assert (config.has_section("Comparison") and
+                    config.has_option("Comparison", "type") and
+                    config.has_option("Comparison", "paths"))
+        except (ConfigParser.Error, AssertionError):
             raise ValueError("Invalid recent comparison file")
 
         comp_type = config.get("Comparison", "type")



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