Skip to content

Commit

Permalink
Support injecting constant arguments in function call
Browse files Browse the repository at this point in the history
  • Loading branch information
Boyan-MILANOV committed Dec 26, 2023
1 parent 16aa3bd commit fee25b6
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions fickling/fickle.py
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,7 @@ def insert_magic_int(self, magic: int, index: int = -1):
def insert_function_call_on_unpickled_object(
self,
function_definition: str,
constant_args: List[Any],
):
"""Insert and call a function that takes the unpickled object as parameter.
Expand Down Expand Up @@ -552,6 +553,10 @@ def insert_function_call_on_unpickled_object(
self.insert(-1, Mark())
self.insert(-1, Get.create(2))

# Add constant arguments
for arg in constant_args:
self.insert(-1, ConstantOpcode.new(arg))

# Now the stack contains [func, mark, model].
# We need to add TUPLE which
# packs the function arguments from the stack and then call REDUCE, which calls the injected
Expand Down Expand Up @@ -1429,6 +1434,9 @@ class ShortBinBytes(DynamicLength, ConstantOpcode):
priority = Unicode.priority + 1
length_bytes = 1

def encode_body(self) -> bytes:
return self.arg

@classmethod
def validate(cls, obj):
if not isinstance(obj, bytes):
Expand Down

0 comments on commit fee25b6

Please sign in to comment.