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

prevent mime type to crash #1016

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading