File tree 3 files changed +19
-8
lines changed 3 files changed +19
-8
lines changed Original file line number Diff line number Diff line change 21
21
"wms-layers-esri-world-imagery-fallback" : "world_imagery_fallback" ,
22
22
"wms-read-timeout" : 600 ,
23
23
"max-nr-simultaneous-uploads" : 100 ,
24
- "max_pixel_per_image" : 10e8 , # 10.000*10.000
25
24
"yolo_cls" : "SMT-CLS" ,
26
25
"yolo_osm_obj" : "SMT-OSM" ,
27
26
"yolo_esri_obj" : "SMT-ESRI" ,
Original file line number Diff line number Diff line change 2
2
from uuid import UUID
3
3
4
4
import PIL .Image as Image
5
+ from PIL .Image import DecompressionBombError
5
6
from werkzeug .datastructures import FileStorage
6
7
7
8
from sketch_map_tool import get_config_value
@@ -27,7 +28,6 @@ def validate_uploaded_sketchmaps(files: list[FileStorage]):
27
28
"""Validation function for uploaded files."""
28
29
29
30
max_nr_simultaneous_uploads = int (get_config_value ("max-nr-simultaneous-uploads" ))
30
- max_pixel_per_image = int (get_config_value ("max_pixel_per_image" ))
31
31
32
32
if len (files ) > max_nr_simultaneous_uploads :
33
33
raise UploadLimitsExceededError (
@@ -38,16 +38,15 @@ def validate_uploaded_sketchmaps(files: list[FileStorage]):
38
38
)
39
39
40
40
for file in files :
41
- img = Image . open ( file )
42
- total_pxl_cnt = img . size [ 0 ] * img . size [ 1 ]
43
- if total_pxl_cnt > max_pixel_per_image :
41
+ try :
42
+ img = Image . open ( file )
43
+ except DecompressionBombError as error :
44
44
raise UploadLimitsExceededError (
45
45
N_ (
46
46
"You can only upload pictures up to "
47
- "a total pixel count of {MAX_PIXEL_PER_IMAGE} ."
47
+ "a total pixel count of 178956970 pixels (128 Mpx) ."
48
48
),
49
- {"MAX_PIXEL_PER_IMAGE" : max_pixel_per_image },
50
- )
49
+ ) from error
51
50
del img
52
51
file .seek (0 )
53
52
Original file line number Diff line number Diff line change
1
+ import PIL
1
2
import pytest
2
3
4
+ from sketch_map_tool .exceptions import UploadLimitsExceededError
3
5
from sketch_map_tool .validators import (
4
6
validate_bbox ,
5
7
validate_type ,
8
+ validate_uploaded_sketchmaps ,
6
9
validate_uuid ,
7
10
)
8
11
@@ -40,3 +43,13 @@ def test_validate_bbox(bbox_wgs84_str):
40
43
def test_validate_bbox_invalid (bbox_str_ ):
41
44
with pytest .raises (ValueError ):
42
45
validate_bbox (bbox_str_ )
46
+
47
+
48
+ def test_validate_uploaded_sketchmaps (file ):
49
+ before = PIL .Image .MAX_IMAGE_PIXELS
50
+ try :
51
+ PIL .Image .MAX_IMAGE_PIXELS = 1
52
+ with pytest .raises (UploadLimitsExceededError ):
53
+ validate_uploaded_sketchmaps ([file ])
54
+ finally :
55
+ PIL .Image .MAX_IMAGE_PIXELS = before
You can’t perform that action at this time.
0 commit comments