Skip to content

Commit a8552b9

Browse files
authored
Merge pull request #1608 from pierotofy/workfix
Handle PIL decompression bomb error
2 parents 334571f + b4586f5 commit a8552b9

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

app/models/task.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
from shutil import copyfile
2020
import requests
2121
from PIL import Image
22+
Image.MAX_IMAGE_PIXELS = 4096000000
2223
from django.contrib.gis.gdal import GDALRaster
2324
from django.contrib.gis.gdal import OGRGeometry
2425
from django.contrib.gis.geos import GEOSGeometry
@@ -159,7 +160,7 @@ def resize_image(image_path, resize_to, done=None):
159160
os.rename(resized_image_path, image_path)
160161

161162
logger.info("Resized {} to {}x{}".format(image_path, resized_width, resized_height))
162-
except (IOError, ValueError, struct.error) as e:
163+
except (IOError, ValueError, struct.error, Image.DecompressionBombError) as e:
163164
logger.warning("Cannot resize {}: {}.".format(image_path, str(e)))
164165
if done is not None:
165166
done()
@@ -595,7 +596,7 @@ def handle_import(self):
595596

596597
fd.write(chunk)
597598

598-
except (requests.exceptions.Timeout, requests.exceptions.ConnectionError, ReadTimeoutError) as e:
599+
except (requests.exceptions.Timeout, requests.exceptions.ConnectionError, ReadTimeoutError, requests.exceptions.MissingSchema) as e:
599600
raise NodeServerError(e)
600601

601602
self.refresh_from_db()
@@ -604,7 +605,9 @@ def handle_import(self):
604605
self.extract_assets_and_complete()
605606
except zipfile.BadZipFile:
606607
raise NodeServerError(gettext("Invalid zip file"))
607-
608+
except NotImplementedError:
609+
raise NodeServerError(gettext("Unsupported compression method"))
610+
608611
images_json = self.assets_path("images.json")
609612
if os.path.exists(images_json):
610613
try:

0 commit comments

Comments
 (0)