From e312868c4edab227b772f4795e8adff96da4bf4d Mon Sep 17 00:00:00 2001 From: jvoisin Date: Mon, 13 Dec 2021 19:00:41 +0100 Subject: [PATCH] Increase a bit the robustness of mat2 Those issues were found via https://github.com/google/atheris --- libmat2/audio.py | 3 ++- libmat2/images.py | 5 ++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/libmat2/audio.py b/libmat2/audio.py index bd7add9..3f3a757 100644 --- a/libmat2/audio.py +++ b/libmat2/audio.py @@ -13,7 +13,8 @@ class MutagenParser(abstract.AbstractParser): def __init__(self, filename): super().__init__(filename) try: - mutagen.File(self.filename) + if mutagen.File(self.filename) is None: + raise ValueError except mutagen.MutagenError: raise ValueError diff --git a/libmat2/images.py b/libmat2/images.py index e55b765..c584c1c 100644 --- a/libmat2/images.py +++ b/libmat2/images.py @@ -26,7 +26,10 @@ class SVGParser(exiftool.ExiftoolParser): } def remove_all(self) -> bool: - svg = Rsvg.Handle.new_from_file(self.filename) + try: + svg = Rsvg.Handle.new_from_file(self.filename) + except GLib.GError: + raise ValueError dimensions = svg.get_dimensions() surface = cairo.SVGSurface(self.output_filename, dimensions.height,