Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixup some invalid pickle testing #924

Merged
merged 1 commit into from
Jul 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions bandit/blacklists/calls.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@
| B301 | pickle | - pickle.loads | Medium |
| | | - pickle.load | |
| | | - pickle.Unpickler | |
| | | - cPickle.loads | |
| | | - cPickle.load | |
| | | - cPickle.Unpickler | |
| | | - dill.loads | |
| | | - dill.load | |
| | | - dill.Unpickler | |
Expand Down Expand Up @@ -347,9 +344,6 @@ def gen_blacklist():
"pickle.loads",
"pickle.load",
"pickle.Unpickler",
"cPickle.loads",
"cPickle.load",
"cPickle.Unpickler",
"dill.loads",
"dill.load",
"dill.Unpickler",
Expand Down
6 changes: 3 additions & 3 deletions examples/dill.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import dill
import StringIO
import io

# dill
pick = dill.dumps({'a': 'b', 'c': 'd'})
print(dill.loads(pick))

file_obj = StringIO.StringIO()
file_obj = io.BytesIO()
dill.dump([1, 2, '3'], file_obj)
file_obj.seek(0)
print(dill.load(file_obj))

file_obj.seek(0)
print(dill.Undillr(file_obj).load())
print(dill.Unpickler(file_obj).load())
18 changes: 2 additions & 16 deletions examples/pickle_deserialize.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,15 @@
import cPickle
import io
import pickle
import StringIO


# pickle
pick = pickle.dumps({'a': 'b', 'c': 'd'})
print(pickle.loads(pick))

file_obj = StringIO.StringIO()
file_obj = io.BytesIO()
pickle.dump([1, 2, '3'], file_obj)
file_obj.seek(0)
print(pickle.load(file_obj))

file_obj.seek(0)
print(pickle.Unpickler(file_obj).load())

# cPickle
serialized = cPickle.dumps({(): []})
print(cPickle.loads(serialized))

file_obj = StringIO.StringIO()
cPickle.dump((1,), file_obj)
file_obj.seek(0)
print(cPickle.load(file_obj))

file_obj.seek(0)
print(cPickle.Unpickler(file_obj).load())

8 changes: 4 additions & 4 deletions tests/functional/test_functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,16 +348,16 @@ def test_os_system(self):
def test_pickle(self):
"""Test for the `pickle` module."""
expect = {
"SEVERITY": {"UNDEFINED": 0, "LOW": 2, "MEDIUM": 6, "HIGH": 0},
"CONFIDENCE": {"UNDEFINED": 0, "LOW": 0, "MEDIUM": 0, "HIGH": 8},
"SEVERITY": {"UNDEFINED": 0, "LOW": 1, "MEDIUM": 3, "HIGH": 0},
"CONFIDENCE": {"UNDEFINED": 0, "LOW": 0, "MEDIUM": 0, "HIGH": 4},
}
self.check_example("pickle_deserialize.py", expect)

def test_dill(self):
"""Test for the `dill` module."""
expect = {
"SEVERITY": {"UNDEFINED": 0, "LOW": 1, "MEDIUM": 2, "HIGH": 0},
"CONFIDENCE": {"UNDEFINED": 0, "LOW": 0, "MEDIUM": 0, "HIGH": 3},
"SEVERITY": {"UNDEFINED": 0, "LOW": 1, "MEDIUM": 3, "HIGH": 0},
"CONFIDENCE": {"UNDEFINED": 0, "LOW": 0, "MEDIUM": 0, "HIGH": 4},
}
self.check_example("dill.py", expect)

Expand Down