diff --git a/avatar/forms.py b/avatar/forms.py index 745bae3..27ffd5e 100644 --- a/avatar/forms.py +++ b/avatar/forms.py @@ -5,6 +5,7 @@ from django.template.defaultfilters import filesizeformat from django.utils.safestring import mark_safe from django.utils.translation import gettext_lazy as _ +from PIL import Image, ImageOps from avatar.conf import settings from avatar.models import Avatar @@ -82,6 +83,12 @@ def clean_avatar(self): } ) + try: + image = Image.open(data) + ImageOps.exif_transpose(image) + except TypeError: + raise forms.ValidationError(_("Corrupted image")) + count = Avatar.objects.filter(user=self.user).count() if 1 < settings.AVATAR_MAX_AVATARS_PER_USER <= count: error = _(