Commit b0fb1b2 1 parent dc88546 commit b0fb1b2 Copy full SHA for b0fb1b2
File tree 1 file changed +4
-15
lines changed
1 file changed +4
-15
lines changed Original file line number Diff line number Diff line change @@ -1106,25 +1106,14 @@ def pull_embedded_pe_files(data, out_dir):
1106
1106
# Is this a Office 2007 (zip) file?
1107
1107
if filetype .is_office2007_file (data , is_data = True ):
1108
1108
1109
- # Write the zip data to a temp file.
1110
- # we use tempfile.NamedTemporaryFile to create a temporary file in a platform-independent
1111
- # and secure way. The file needs to be accessible with a filename until it is explicitly
1112
- # deleted (hence the option delete=False).
1113
- # TODO: [Phil] I think we could avoid this and use a bytes buffer in memory instead, zipfile supports it
1114
- # This is really required on Windows because the antivirus blocks the temp file on disk
1115
- f = tempfile .NamedTemporaryFile (delete = False )
1116
- fname = f .name
1117
- f .write (data )
1118
- f .close ()
1119
-
1109
+ # convert data to a BytesIO buffer so that we can use zipfile in memory
1110
+ # without writing a temp file on disk:
1111
+ data_io = io .BytesIO (data )
1120
1112
# Pull embedded PE files from each file in the zip.
1121
- with zipfile .ZipFile (fname , "r" ) as f :
1113
+ with zipfile .ZipFile (data_io , "r" ) as f :
1122
1114
for name in f .namelist ():
1123
1115
curr_data = f .read (name )
1124
1116
pull_embedded_pe_files (curr_data , out_dir )
1125
-
1126
- # Clean up and leave.
1127
- os .remove (fname )
1128
1117
return
1129
1118
1130
1119
# Is a PE file in the data at all?
You can’t perform that action at this time.
0 commit comments