Skip to content

Commit

Permalink
Add pickle version as part of clcache version
Browse files Browse the repository at this point in the history
This way we make sure that we unpickle only objects with a supported
pickle format version.
  • Loading branch information
olebole committed Apr 13, 2022
1 parent 198f6bb commit df93165
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
3 changes: 2 additions & 1 deletion pyraf/clcache.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@


def _currentVersion():
return "4e" if pyrafglobals._use_ecl else "4c"
v = "4e" if pyrafglobals._use_ecl else "4c"
return v + str(sqliteshelve.pickle_version)


class _FileContentsCache(filecache.FileCacheDict):
Expand Down
6 changes: 5 additions & 1 deletion pyraf/sqliteshelve.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@
import os


pickle_protocol = 4
"""Protocol version to use for pickling objects"""


class Shelf:
"""An SQLite implementation of the Python Shelf interface
Expand Down Expand Up @@ -75,7 +79,7 @@ def __setitem__(self, key, value):
"""
if self.readonly:
raise OSError("Readonly database")
pdata = pickle.dumps(value, protocol=4)
pdata = pickle.dumps(value, protocol=pickle_protocol)
cursor = self.db.cursor()
try:
cursor.execute("insert or replace into shelf (key_str, value_str)"
Expand Down

0 comments on commit df93165

Please sign in to comment.