diff options
Diffstat (limited to 'libmat2')
| -rw-r--r-- | libmat2/office.py | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/libmat2/office.py b/libmat2/office.py index 90f7c7a..914fd39 100644 --- a/libmat2/office.py +++ b/libmat2/office.py | |||
| @@ -40,7 +40,7 @@ class ArchiveBasedAbstractParser(abstract.AbstractParser): | |||
| 40 | 40 | ||
| 41 | 41 | ||
| 42 | def _clean_internal_file(self, item: zipfile.ZipInfo, temp_folder: str, | 42 | def _clean_internal_file(self, item: zipfile.ZipInfo, temp_folder: str, |
| 43 | zin: zipfile.ZipFile, zout: zipfile.ZipFile): | 43 | zin: zipfile.ZipFile, zout: zipfile.ZipFile) -> bool: |
| 44 | output = '' | 44 | output = '' |
| 45 | zin.extract(member=item, path=temp_folder) | 45 | zin.extract(member=item, path=temp_folder) |
| 46 | if item.filename not in self.whitelist: | 46 | if item.filename not in self.whitelist: |
| @@ -48,7 +48,7 @@ class ArchiveBasedAbstractParser(abstract.AbstractParser): | |||
| 48 | tmp_parser, mtype = parser_factory.get_parser(full_path) # type: ignore | 48 | tmp_parser, mtype = parser_factory.get_parser(full_path) # type: ignore |
| 49 | if not tmp_parser: | 49 | if not tmp_parser: |
| 50 | print("%s's format (%s) isn't supported" % (item.filename, mtype)) | 50 | print("%s's format (%s) isn't supported" % (item.filename, mtype)) |
| 51 | return | 51 | return False |
| 52 | tmp_parser.remove_all() | 52 | tmp_parser.remove_all() |
| 53 | output = tmp_parser.output_filename | 53 | output = tmp_parser.output_filename |
| 54 | else: | 54 | else: |
| @@ -57,6 +57,7 @@ class ArchiveBasedAbstractParser(abstract.AbstractParser): | |||
| 57 | clean_zinfo = self._clean_zipinfo(zinfo) | 57 | clean_zinfo = self._clean_zipinfo(zinfo) |
| 58 | with open(output, 'rb') as f: | 58 | with open(output, 'rb') as f: |
| 59 | zout.writestr(clean_zinfo, f.read()) | 59 | zout.writestr(clean_zinfo, f.read()) |
| 60 | return True | ||
| 60 | 61 | ||
| 61 | 62 | ||
| 62 | class MSOfficeParser(ArchiveBasedAbstractParser): | 63 | class MSOfficeParser(ArchiveBasedAbstractParser): |
| @@ -104,7 +105,10 @@ class MSOfficeParser(ArchiveBasedAbstractParser): | |||
| 104 | zout.writestr(item, zin.read(item)) | 105 | zout.writestr(item, zin.read(item)) |
| 105 | continue | 106 | continue |
| 106 | 107 | ||
| 107 | self._clean_internal_file(item, temp_folder, zin, zout) | 108 | if self._clean_internal_file(item, temp_folder, zin, zout) is False: |
| 109 | zout.close() | ||
| 110 | os.remove(self.output_filename) | ||
| 111 | return False | ||
| 108 | 112 | ||
| 109 | shutil.rmtree(temp_folder) | 113 | shutil.rmtree(temp_folder) |
| 110 | zout.close() | 114 | zout.close() |
| @@ -156,7 +160,9 @@ class LibreOfficeParser(ArchiveBasedAbstractParser): | |||
| 156 | elif item.filename == 'meta.xml': | 160 | elif item.filename == 'meta.xml': |
| 157 | continue # don't keep metadata files | 161 | continue # don't keep metadata files |
| 158 | 162 | ||
| 159 | self._clean_internal_file(item, temp_folder, zin, zout) | 163 | if self._clean_internal_file(item, temp_folder, zin, zout) is False: |
| 164 | os.remove(self.output_filename) | ||
| 165 | return False | ||
| 160 | 166 | ||
| 161 | shutil.rmtree(temp_folder) | 167 | shutil.rmtree(temp_folder) |
| 162 | zout.close() | 168 | zout.close() |
