diff --git a/libmat2/office.py b/libmat2/office.py index a5a49cfe0f93ecfa75838803b8f94bbdaa234246..aea56b9b6d91361ab8846b5ebe5c07ebfbc5ba8b 100644 --- a/libmat2/office.py +++ b/libmat2/office.py @@ -16,6 +16,13 @@ class ArchiveBasedAbstractParser(abstract.AbstractParser): files_to_keep = set() # type: Set[str] files_to_omit = set() # type: Set[Pattern] + def __init__(self, filename): + super().__init__(filename) + try: # better fail here than later + zipfile.ZipFile(self.filename) + except zipfile.BadZipFile: + raise ValueError + def _clean_zipinfo(self, zipinfo: zipfile.ZipInfo) -> zipfile.ZipInfo: zipinfo.create_system = 3 # Linux zipinfo.comment = b'' diff --git a/tests/test_libmat2.py b/tests/test_libmat2.py index 4b312dedd3cf43c4e35a16e819922bb42b950d5f..e1d949d539ce811c2e9c1cd7b172fdf415553750 100644 --- a/tests/test_libmat2.py +++ b/tests/test_libmat2.py @@ -90,6 +90,11 @@ class TestCorruptedFiles(unittest.TestCase): os.remove('./tests/data/clean.torrent') + def test_odg(self): + shutil.copy('./tests/data/dirty.png', './tests/data/clean.odg') + with self.assertRaises(ValueError): + office.LibreOfficeParser('./tests/data/clean.odg') + class TestGetMeta(unittest.TestCase): def test_pdf(self): p = pdf.PDFParser('./tests/data/dirty.pdf')