Merge pull request #1608 from pierotofy/workfix

Handle PIL decompression bomb error
pull/1611/head v2.7.0
Piero Toffanin 2025-02-16 13:26:31 +01:00 zatwierdzone przez GitHub
commit a8552b9722
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: B5690EEEBB952194
1 zmienionych plików z 6 dodań i 3 usunięć

Wyświetl plik

@ -19,6 +19,7 @@ import rasterio
from shutil import copyfile
import requests
from PIL import Image
Image.MAX_IMAGE_PIXELS = 4096000000
from django.contrib.gis.gdal import GDALRaster
from django.contrib.gis.gdal import OGRGeometry
from django.contrib.gis.geos import GEOSGeometry
@ -159,7 +160,7 @@ def resize_image(image_path, resize_to, done=None):
os.rename(resized_image_path, image_path)
logger.info("Resized {} to {}x{}".format(image_path, resized_width, resized_height))
except (IOError, ValueError, struct.error) as e:
except (IOError, ValueError, struct.error, Image.DecompressionBombError) as e:
logger.warning("Cannot resize {}: {}.".format(image_path, str(e)))
if done is not None:
done()
@ -595,7 +596,7 @@ class Task(models.Model):
fd.write(chunk)
except (requests.exceptions.Timeout, requests.exceptions.ConnectionError, ReadTimeoutError) as e:
except (requests.exceptions.Timeout, requests.exceptions.ConnectionError, ReadTimeoutError, requests.exceptions.MissingSchema) as e:
raise NodeServerError(e)
self.refresh_from_db()
@ -604,7 +605,9 @@ class Task(models.Model):
self.extract_assets_and_complete()
except zipfile.BadZipFile:
raise NodeServerError(gettext("Invalid zip file"))
except NotImplementedError:
raise NodeServerError(gettext("Unsupported compression method"))
images_json = self.assets_path("images.json")
if os.path.exists(images_json):
try: