Skip to content
This repository has been archived by the owner on Jun 24, 2024. It is now read-only.

Commit

Permalink
prevent mime type to crash
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexandreJunod committed Jun 3, 2024
1 parent 41282be commit a1706e5
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion geocity/apps/api/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from io import BytesIO

from django.conf import settings
from django.core.exceptions import SuspiciousOperation
from django.db.models import Q
from django.utils.text import get_valid_filename
from PIL import Image
Expand All @@ -22,7 +23,11 @@ def get_mime_type(content):
"""
Used to retrieve mime type in response.content of request
"""
image = Image.open(BytesIO(content))
try:
image = Image.open(BytesIO(content))
except:
raise SuspiciousOperation

image_format = image.format
mime_type = "image/" + image_format.lower()
return mime_type
Expand Down

0 comments on commit a1706e5

Please sign in to comment.