Start slice and build list on Python3. Do sanity check on marshal load

of code.
This commit is contained in:
rocky
2015-12-21 06:39:01 -05:00
parent 9cdcdfd305
commit 5dc3af3238
6 changed files with 33 additions and 15 deletions

View File

@@ -41,12 +41,19 @@ def load_code(fp, magic_int):
"""
global internStrings
internStrings = []
seek_pos = fp.tell()
# Do a sanity check. Is this a code type?
if fp.read(1).decode('utf-8') != 'c':
raise TypeError("File %s doesn't smell like Python bytecode" % fp.name)
fp.seek(seek_pos)
return load_code_internal(fp, magic_int)
def load_code_internal(fp, magic_int, bytes_for_s=False):
global internStrings
marshalType = fp.read(1).decode('utf-8')
b1 = fp.read(1)
marshalType = b1.decode('utf-8')
if marshalType == 'c':
Code = types.CodeType