Commit 6ed43a18 authored by Jim Fulton's avatar Jim Fulton

Make is_blob_record tolerant of invalid pickles.

parent 5de7b02f
......@@ -745,4 +745,9 @@ def is_blob_record(record):
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
......@@ -589,7 +589,7 @@ def loadblob_tmpstore():
"""
def is_blob_record():
"""
r"""
>>> fs = FileStorage('Data.fs')
>>> bs = ZODB.blob.BlobStorage('blobs', fs)
>>> db = DB(bs)
......@@ -601,6 +601,15 @@ def is_blob_record():
>>> 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()
"""
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment