From 97947e61c11e9029c33bc54ade91becfedca5c60 Mon Sep 17 00:00:00 2001 From: Io Mintz Date: Thu, 10 Oct 2019 00:27:38 +0000 Subject: [PATCH] add-archive: ignore invalid files allows uploading, for example, a zip file with a LICENSE --- cogs/emote.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/cogs/emote.py b/cogs/emote.py index 30a738f..f24e100 100644 --- a/cogs/emote.py +++ b/cogs/emote.py @@ -197,7 +197,8 @@ class Emotes(commands.Cog): """Add several emotes from a .zip or .tar archive. You may either pass a URL to an archive or upload one as an attachment. - All .gif, .png, and .jpg files in the archive will be uploaded as emotes. + All valid GIF, PNG, and JPEG files in the archive will be uploaded as emotes. + The rest will be ignored. """ if url and context.message.attachments: raise commands.BadArgument('Either a URL or an attachment must be given, not both.') @@ -219,6 +220,10 @@ class Emotes(commands.Cog): async def add_from_archive(self, context, archive): limit = 50_000_000 # prevent someone from trying to make a giant compressed file async for name, img, error in utils.archive.extract_async(io.BytesIO(archive), size_limit=limit): + try: + utils.image.mime_type_for_image(img) + except errors.InvalidImageError: + continue if error is None: name = self.format_emote_filename(posixpath.basename(name)) async with context.typing():