Archive analyzer that looks for suspicious entries and unpacks the archive for recursive analysis
(*, location: ScanLocation)
| 173 | |
| 174 | |
| 175 | def archive_analyzer(*, location: ScanLocation) -> AnalyzerReturnType: |
| 176 | """ |
| 177 | Archive analyzer that looks for suspicious entries and unpacks the archive for recursive analysis |
| 178 | """ |
| 179 | if location.location.is_dir(): |
| 180 | return |
| 181 | elif location.metadata.get("source") == "diff": |
| 182 | return |
| 183 | |
| 184 | mime = location.metadata["mime"] |
| 185 | if mime not in SUPPORTED_MIME: |
| 186 | return |
| 187 | |
| 188 | tmp_dir = tempfile.mkdtemp(prefix="aura_pkg__sandbox", suffix=os.path.basename(location.location)) |
| 189 | logger.info("Extracting to: '{}' [{}]".format(tmp_dir, mime)) |
| 190 | |
| 191 | yield location.create_child( |
| 192 | parent=location, |
| 193 | new_location=tmp_dir, |
| 194 | cleanup=True, |
| 195 | ) |
| 196 | |
| 197 | try: |
| 198 | yield from extract(location=location, destination=tmp_dir) |
| 199 | except (tarfile.ReadError, zipfile.BadZipFile, EOFError) as exc: |
| 200 | yield ArchiveAnomaly.from_generic_exception(location, exc) |
| 201 | |
| 202 | |
| 203 | def diff_archive(diff) -> AnalyzerReturnType: |
no test coverage detected