gnome-games r8911 - trunk/gnome-sudoku/src/lib



Author: thomashpa
Date: Sat Mar 28 02:05:39 2009
New Revision: 8911
URL: http://svn.gnome.org/viewvc/gnome-games?rev=8911&view=rev

Log:
Don't crash on malformed save file. Fixes bug #516491

Modified:
   trunk/gnome-sudoku/src/lib/saver.py

Modified: trunk/gnome-sudoku/src/lib/saver.py
==============================================================================
--- trunk/gnome-sudoku/src/lib/saver.py	(original)
+++ trunk/gnome-sudoku/src/lib/saver.py	Sat Mar 28 02:05:39 2009
@@ -211,8 +211,22 @@
             except:
                 print 'Warning: could not read file',f
             else:
-                jar['saved_at']=os.stat(f)[8]
-                games.append(jar)
+                if self.is_valid(jar):
+                    jar['saved_at']=os.stat(f)[8]
+                    games.append(jar)
+                else:
+                    print 'Warning: malformed save game',f
         return games
-        
+
+    def is_valid (self, jar):
+        virgin = jar['game'].split('\n')[0].replace(' ','')
+        played = jar['game'].split('\n')[1].replace(' ','')
+
+        if len(virgin) != 81 or len(played) != 81:
+            return False
+
+        if not virgin.isdigit() or not played.isdigit():
+            return False
+
+        return True
 



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