Skip to content

Commit f0813c5

Browse files
committed
Seek to 0 before reading
1 parent ee63631 commit f0813c5

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

apkid/apkid.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ def scan_file(self, file_path: str) -> Dict[str, List[yara.Match]]:
116116
with open(file_path, 'rb') as f:
117117
if not self._should_scan(f, filename):
118118
return results
119-
119+
f.seek(0)
120120
matches: List[yara.Matches] = self.rules.match(data=f.read(), timeout=self.options.timeout)
121121
if len(matches) > 0:
122122
results[filename] = matches
@@ -151,13 +151,14 @@ def _scan_zip_entry(self, zf, info, results, depth) -> None:
151151
entry_buffer.seek(0)
152152
if not self._should_scan(entry_buffer, info.filename):
153153
return
154-
entry_buffer.seek(4)
155154
entry_buffer.write(entry.read())
155+
entry_buffer.seek(0)
156156
matches = self.rules.match(data=entry_buffer.read(), timeout=self.options.timeout)
157157

158158
if len(matches) > 0:
159159
results[info.filename] = matches
160160

161+
entry_buffer.seek(0)
161162
if depth < self.options.scan_depth and self._is_zipfile(entry_buffer, info.filename):
162163
with zipfile.ZipFile(entry_buffer) as zip_entry:
163164
nested_results = self._scan_zip(zip_entry, depth=depth + 1)
@@ -167,7 +168,6 @@ def _scan_zip_entry(self, zf, info, results, depth) -> None:
167168
@staticmethod
168169
def _type_file(file_obj: IO) -> Union[None, str]:
169170
magic = file_obj.read(4)
170-
file_obj.seek(0)
171171
for file_type, magics in SCANNABLE_FILE_MAGICS.items():
172172
if magic in magics:
173173
return file_type

0 commit comments

Comments
 (0)