examples of a safe Unpickler?

Kevin Altis altis at semi-retired.com
Thu Jul 18 19:38:16 EDT 2002


The Security section of the pickle module documentation:

http://www.python.org/doc/current/lib/pickle-sec.html

talks about creating a safe unpickler. We're exploring using pickles as a
basic storage format with PythonCard and I would like to be able to load a
file without any chance for a rogue pickle file becoming a security problem.
It is expected that users will exchange pickled data files via email,
download them from web sites, etc. so while the data written by a given app
will always be simple data types, there is no way of knowing that about the
pickle when it is loaded. I just want to store built-in data types, lists,
and dictionaries, no custom classes or functions. This is an alternative to
using something like XML, where the overhead of loading and parsing a large
file to turn it back into say a list of dictionaries can take quite a long
time and thus is unacceptable for primary storage.

So, are there examples of an unpickler (preferably based on cPickle for
speed)? It is not clear to me from the documentation what I actually need to
do. The docs seem to imply that if an object is not marked as
__safe_for_unpickling__  then an UnpicklingError exception might be thrown
just using the default Unpickler, but if so, I would need an example or two
of a pickle with a security problem to test this. Throwing an exception
would be fine. It would be nice if there was a separate
UnpicklingSecurityError exception.

Thanks,

ka
---
Kevin Altis
altis at semi-retired.com





More information about the Python-list mailing list