gnome-games r9005 - branches/gnome-2-26/gnome-sudoku/src/lib



Author: thomashpa
Date: Tue Apr  7 00:39:09 2009
New Revision: 9005
URL: http://svn.gnome.org/viewvc/gnome-games?rev=9005&view=rev

Log:
Ignore malformed savegames. Bug #516491

Modified:
   branches/gnome-2-26/gnome-sudoku/src/lib/saver.py

Modified: branches/gnome-2-26/gnome-sudoku/src/lib/saver.py
==============================================================================
--- branches/gnome-2-26/gnome-sudoku/src/lib/saver.py	(original)
+++ branches/gnome-2-26/gnome-sudoku/src/lib/saver.py	Tue Apr  7 00:39:09 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]