[Zodb-checkins] SVN: ZODB/trunk/src/ZODB/blob.py Made is_blob_record much faster and more secure.
Jim Fulton
jim at zope.com
Mon Aug 24 14:17:55 EDT 2009
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
More information about the Zodb-checkins
mailing list