File tree Expand file tree Collapse file tree 2 files changed +11
-3
lines changed Expand file tree Collapse file tree 2 files changed +11
-3
lines changed Original file line number Diff line number Diff line change @@ -170,7 +170,11 @@ def save_memory_cache(self, filepath: str) -> None:
170170 with open (filepath , "wb" ) as f :
171171 cloudpickle .dump (self .memory_cache , f )
172172
173- def load_memory_cache (self , filepath : str ) -> None :
173+ def load_memory_cache (self , filepath : str , allow_pickle : bool = False ) -> None :
174+ if not allow_pickle :
175+ raise ValueError ("Loading untrusted .pkl files can run arbitrary code, which may be dangerous. \
176+ Set `allow_pickle=True` to load if you are running in a trusted environment and the file is from a trusted source." )
177+
174178 if not self .enable_memory_cache :
175179 return
176180
Original file line number Diff line number Diff line change @@ -189,8 +189,12 @@ def test_save_and_load_memory_cache(cache, tmp_path):
189189 memory_max_entries = 100 ,
190190 )
191191
192- # Load the memory cache
193- new_cache .load_memory_cache (str (temp_cache_file ))
192+ # Load the memory cache without allowing pickle (default)
193+ with pytest .raises (ValueError ):
194+ new_cache .load_memory_cache (str (temp_cache_file ))
195+
196+ # Load the memory cache with allow_pickle=True
197+ new_cache .load_memory_cache (str (temp_cache_file ), allow_pickle = True )
194198
195199 # Verify items are in the new memory cache
196200 for req in requests :
You can’t perform that action at this time.
0 commit comments