Skip to content

Commit 1b61296

Browse files
committed
Python: Model pickle.load
1 parent 27c368a commit 1b61296

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

python/ql/lib/semmle/python/frameworks/Stdlib.qll

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,22 @@ private module StdlibPrivate {
450450
/** Gets a reference to any of the `pickle` modules. */
451451
API::Node pickle() { result = API::moduleImport(["pickle", "cPickle", "_pickle"]) }
452452

453+
/**
454+
* A call to `pickle.load`
455+
* See https://docs.python.org/3/library/pickle.html#pickle.load
456+
*/
457+
private class PickleLoadCall extends Decoding::Range, DataFlow::CallCfgNode {
458+
PickleLoadCall() { this = pickle().getMember("load").getACall() }
459+
460+
override predicate mayExecuteInput() { any() }
461+
462+
override DataFlow::Node getAnInput() { result in [this.getArg(0), this.getArgByName("file")] }
463+
464+
override DataFlow::Node getOutput() { result = this }
465+
466+
override string getFormat() { result = "pickle" }
467+
}
468+
453469
/**
454470
* A call to `pickle.loads`
455471
* See https://docs.python.org/3/library/pickle.html#pickle.loads

python/ql/test/library-tests/frameworks/stdlib/Decoding.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
import shelve
44
import base64
55

6-
pickle.load(file_) # $ MISSING: decodeInput=file_ decodeOutput=pickle.load(..) decodeFormat=pickle decodeMayExecuteInput
7-
pickle.load(file=file_) # $ MISSING: decodeInput=file_ decodeOutput=pickle.load(..) decodeFormat=pickle decodeMayExecuteInput
6+
pickle.load(file_) # $ decodeInput=file_ decodeOutput=pickle.load(..) decodeFormat=pickle decodeMayExecuteInput
7+
pickle.load(file=file_) # $ decodeInput=file_ decodeOutput=pickle.load(..) decodeFormat=pickle decodeMayExecuteInput
88
pickle.loads(payload) # $ decodeInput=payload decodeOutput=pickle.loads(..) decodeFormat=pickle decodeMayExecuteInput
99
# using this keyword argument is disallowed from Python 3.9
1010
pickle.loads(data=payload) # $ decodeInput=payload decodeOutput=pickle.loads(..) decodeFormat=pickle decodeMayExecuteInput

0 commit comments

Comments
 (0)