Commit a3b87052 authored by Jim Fulton's avatar Jim Fulton

Make is_blob_record tolerant of invalid pickles.

parent 94a73a5e
...@@ -745,4 +745,9 @@ def is_blob_record(record): ...@@ -745,4 +745,9 @@ def is_blob_record(record):
storage to another. 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(): ...@@ -589,7 +589,7 @@ def loadblob_tmpstore():
""" """
def is_blob_record(): def is_blob_record():
""" r"""
>>> fs = FileStorage('Data.fs') >>> fs = FileStorage('Data.fs')
>>> bs = ZODB.blob.BlobStorage('blobs', fs) >>> bs = ZODB.blob.BlobStorage('blobs', fs)
>>> db = DB(bs) >>> db = DB(bs)
...@@ -601,6 +601,15 @@ def is_blob_record(): ...@@ -601,6 +601,15 @@ def is_blob_record():
>>> ZODB.blob.is_blob_record(fs.load(ZODB.utils.p64(1), '')[0]) >>> ZODB.blob.is_blob_record(fs.load(ZODB.utils.p64(1), '')[0])
True 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() >>> 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