From a0656b52cd154404984e0c2323dd112838661b31 Mon Sep 17 00:00:00 2001 From: Magnus Hagander Date: Tue, 12 Dec 2023 08:38:46 +0100 Subject: [PATCH] Accept MPO files in twitter interface Pillow misidentifies JPG as MPO it seems, so let's see if it works if we just accept MPO as well.. --- postgresqleu/confreg/twitter.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/postgresqleu/confreg/twitter.py b/postgresqleu/confreg/twitter.py index 8204a0326..5316fc53f 100644 --- a/postgresqleu/confreg/twitter.py +++ b/postgresqleu/confreg/twitter.py @@ -172,12 +172,14 @@ def volunteer_twitter(request, urlname, token): if 'image' in request.FILES: t.image = request.FILES['image'].read() # Actually validate that it loads as PNG or JPG + # XXX: Pillow issue https://github.com/python-pillow/Pillow/issues/1138 misidentifies JPG + # as MPO. So we should apparenty accept MPO as well.. try: p = ImageFile.Parser() p.feed(t.image) p.close() image = p.image - if image.format not in ('PNG', 'JPEG'): + if image.format not in ('PNG', 'JPEG', 'MPO'): return _json_response({'error': 'Image must be PNG or JPEG, not {}'.format(image.format)}) except Exception as e: return _json_response({'error': 'Failed to parse image'})