SVN: ZODB/trunk/src/ZODB/blob.py Made is_blob_record much faster and more secure.

Jim Fulton <[email protected]>
Newsgroups gmane.comp.python.zope.zodb.cvs
Message-ID <[email protected]>
Log message for revision 103175:
  Made is_blob_record much faster and more secure.
  

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

-=-
Modified: ZODB/trunk/src/ZODB/blob.py
===================================================================
--- ZODB/trunk/src/ZODB/blob.py	2009-08-24 18:17:52 UTC (rev 103174)
+++ ZODB/trunk/src/ZODB/blob.py	2009-08-24 18:17:54 UTC (rev 103175)
@@ -15,6 +15,7 @@
 """
 
 import cPickle
+import cStringIO
 import base64
 import binascii
 import logging
@@ -934,6 +935,10 @@
     link_or_copy = os.link
 
 
+def find_global_Blob(module, class_):
+    if module == 'ZODB.blob' and class_ == 'Blob':
+        return Blob
+
 def is_blob_record(record):
     """Check whether a database record is a blob record.
 
@@ -941,9 +946,15 @@
     storage to another.
 
     """
-    try:
-        return cPickle.loads(record) is ZODB.blob.Blob
-    except (MemoryError, KeyboardInterrupt, SystemExit):
-        raise
-    except Exception:
-        return False
+    if 'ZODB.blob' in record:
+        unpickler = cPickle.Unpickler(cStringIO.StringIO(record))
+        unpickler.find_global = find_global_Blob
+
+        try:
+            return unpickler.load() is Blob
+        except (MemoryError, KeyboardInterrupt, SystemExit):
+            raise
+        except Exception:
+            pass
+
+    return False
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.