[Zodb-checkins] SVN: ZODB/trunk/src/ZODB/ Make is_blob_record tolerant of invalid pickles.

Jim Fulton jim at zope.com
Tue Oct 21 15:46:39 EDT 2008


Log message for revision 92450:
  Make is_blob_record tolerant of invalid pickles.
  

Changed:
  U   ZODB/trunk/src/ZODB/blob.py
  U   ZODB/trunk/src/ZODB/tests/testblob.py

-=-
Modified: ZODB/trunk/src/ZODB/blob.py
===================================================================
--- ZODB/trunk/src/ZODB/blob.py	2008-10-21 19:16:51 UTC (rev 92449)
+++ ZODB/trunk/src/ZODB/blob.py	2008-10-21 19:46:38 UTC (rev 92450)
@@ -745,4 +745,9 @@
     storage to another.
     
     """
-    return cPickle.loads(record) is ZODB.blob.Blob
+    try:
+        return cPickle.loads(record) is ZODB.blob.Blob
+    except (MemoryError, KeyboardInterrupt, SystemExit):
+        raise
+    except Exception:
+        return False

Modified: ZODB/trunk/src/ZODB/tests/testblob.py
===================================================================
--- ZODB/trunk/src/ZODB/tests/testblob.py	2008-10-21 19:16:51 UTC (rev 92449)
+++ ZODB/trunk/src/ZODB/tests/testblob.py	2008-10-21 19:46:38 UTC (rev 92450)
@@ -589,7 +589,7 @@
 """
 
 def is_blob_record():
-    """
+    r"""
     >>> fs = FileStorage('Data.fs')
     >>> bs = ZODB.blob.BlobStorage('blobs', fs)
     >>> db = DB(bs)
@@ -601,6 +601,15 @@
     >>> ZODB.blob.is_blob_record(fs.load(ZODB.utils.p64(1), '')[0])
     True
 
+    An invalid pickle yields a false value:
+
+    >>> ZODB.blob.is_blob_record("Hello world!")
+    False
+    >>> ZODB.blob.is_blob_record('c__main__\nC\nq\x01.')
+    False
+    >>> ZODB.blob.is_blob_record('cWaaaa\nC\nq\x01.')
+    False
+
     >>> db.close()
     """
 



More information about the Zodb-checkins mailing list