diff --git a/libmat2/images.py b/libmat2/images.py index bca1e74abfa4300654c9f9dd1f40817806a8c38e..317a9e308dd799755f63d3f2eb93cadca23578fc 100644 --- a/libmat2/images.py +++ b/libmat2/images.py @@ -196,3 +196,15 @@ class HEICParser(exiftool.ExiftoolParser): def remove_all(self) -> bool: return self._lightweight_cleanup() + +class WEBPParser(GdkPixbufAbstractParser): + mimetypes = {'image/webp'} + meta_allowlist = {'SourceFile', 'ExifToolVersion', 'FileName', + 'Directory', 'FileSize', 'FileModifyDate', + 'FileAccessDate', "FileInodeChangeDate", + 'FilePermissions', 'FileType', 'FileTypeExtension', + 'MIMEType', 'ImageWidth', 'ImageSize', 'BitsPerSample', + 'ColorComponents', 'EncodingProcess', 'JFIFVersion', + 'ResolutionUnit', 'XResolution', 'YCbCrSubSampling', + 'YResolution', 'Megapixels', 'ImageHeight', 'Orientation', + 'HorizontalScale', 'VerticalScale', 'VP8Version'} diff --git a/tests/data/dirty.webp b/tests/data/dirty.webp new file mode 100644 index 0000000000000000000000000000000000000000..0d0e42cbfe18ecf0431b77e762eec15106d2bc12 Binary files /dev/null and b/tests/data/dirty.webp differ diff --git a/tests/test_climat2.py b/tests/test_climat2.py index 923825369c7350714ef1778bc73eba319626e6a6..edc8e885bfb14eeba8972599415702fa7d258baf 100644 --- a/tests/test_climat2.py +++ b/tests/test_climat2.py @@ -236,6 +236,11 @@ class TestGetMeta(unittest.TestCase): self.assertIn(b'i am a : various comment', stdout) self.assertIn(b'artist: jvoisin', stdout) + def test_webp(self): + proc = subprocess.Popen(mat2_binary + ['--show', './tests/data/dirty.webp'], + stdout=subprocess.PIPE) + stdout, _ = proc.communicate() + self.assertIn(b'Warning: [minor] Improper EXIF header', stdout) class TestControlCharInjection(unittest.TestCase): def test_jpg(self): diff --git a/tests/test_libmat2.py b/tests/test_libmat2.py index 19252011f3bd0af678c863680008e800b1e18dff..332a5a349362d143b78b5dbefb4f7eb5d76b70f8 100644 --- a/tests/test_libmat2.py +++ b/tests/test_libmat2.py @@ -113,6 +113,11 @@ class TestGetMeta(unittest.TestCase): meta = p.get_meta() self.assertEqual(meta['Comment'], 'Created with GIMP') + def test_webp(self): + p = images.WEBPParser('./tests/data/dirty.webp') + meta = p.get_meta() + self.assertEqual(meta['Warning'], '[minor] Improper EXIF header') + def test_ppm(self): p = images.PPMParser('./tests/data/dirty.ppm') meta = p.get_meta() @@ -333,6 +338,11 @@ class TestCleaning(unittest.TestCase): 'parser': images.JPGParser, 'meta': {'Comment': 'Created with GIMP'}, 'expected_meta': {}, + }, { + 'name': 'webp', + 'parser': images.WEBPParser, + 'meta': {'Warning': '[minor] Improper EXIF header'}, + 'expected_meta': {}, }, { 'name': 'wav', 'parser': audio.WAVParser, diff --git a/tests/test_lightweight_cleaning.py b/tests/test_lightweight_cleaning.py index ce7e48cc08537155ffb75ba4864241e2a0c2a42e..9b33df4d4563853b1218cfe2bf323bd0c5e124c6 100644 --- a/tests/test_lightweight_cleaning.py +++ b/tests/test_lightweight_cleaning.py @@ -23,6 +23,11 @@ class TestLightWeightCleaning(unittest.TestCase): 'parser': images.JPGParser, 'meta': {'Comment': 'Created with GIMP'}, 'expected_meta': {}, + }, { + 'name': 'webp', + 'parser': images.WEBPParser, + 'meta': {'Warning': '[minor] Improper EXIF header'}, + 'expected_meta': {}, }, { 'name': 'torrent', 'parser': torrent.TorrentParser,