-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathpickle_load-example.py
More file actions
47 lines (36 loc) · 1.39 KB
/
pickle_load-example.py
File metadata and controls
47 lines (36 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# pickle load example
# WARNING: pickle.load() can execute arbitrary code and should only be used
# with trusted data. For untrusted data, use safer alternatives like JSON.
# See: https://docs.python.org/3/library/pickle.html#module-pickle
import pickle
import random
import os
# Only load pickle files from trusted sources in trusted locations
pickle_file = 'assets/discordia.pkl'
# Verify the file exists and is in the expected location
if not os.path.exists(pickle_file):
raise FileNotFoundError(f"Pickle file not found: {pickle_file}")
# Resolve to absolute path to prevent path traversal
pickle_file = os.path.abspath(pickle_file)
expected_dir = os.path.abspath('assets')
if not pickle_file.startswith(expected_dir):
raise ValueError("Pickle file must be in the assets directory")
with open(pickle_file, 'rb') as f:
# SECURITY NOTE: This loads a pickle file that must be from a trusted source
# Never load pickle files from untrusted sources (user uploads, internet, etc.)
discordia = pickle.load(f)
def getran(tex):
texter = random.choice(tex)
if len(texter) < 140 and len(texter) > 0:
return texter
else:
globular = getran(tex)
return globular
def to140(data):
loser = []
for listitem in data:
if len(listitem) < 140 and len(listitem) > 0:
loser.append(listitem)
return loser
print(getran(discordia))
exit('there ya go')