diff --git a/libmat2/images.py b/libmat2/images.py index bca1e74..317a9e3 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 0000000..0d0e42c Binary files /dev/null and b/tests/data/dirty.webp differ diff --git a/tests/test_climat2.py b/tests/test_climat2.py index 9238253..edc8e88 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 1925201..332a5a3 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 ce7e48c..9b33df4 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,