Skip to content

Commit 4bd0ddc

Browse files
committed
simulated_setup_from_image: restore PIL.Image.MAX_IMAGE_PIXELS after reading image.
1 parent d72079c commit 4bd0ddc

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

microscope/simulators/stage_aware_camera.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,17 @@ def simulated_setup_from_image(
138138
conf={'filepath': path_to_image_file}),
139139
]
140140
"""
141-
PIL.Image.MAX_IMAGE_PIXELS = None
142-
image = np.array(PIL.Image.open(filepath))
141+
# PIL will error if trying to open very large images to avoid
142+
# decompression bomb DOS attack. However, this is used to fake a
143+
# stage and will really have very very large images, so remove
144+
# remove the PIL limit temporarily.
145+
original_pil_max_image_pixels = PIL.Image.MAX_IMAGE_PIXELS
146+
try:
147+
PIL.Image.MAX_IMAGE_PIXELS = None
148+
image = np.array(PIL.Image.open(filepath))
149+
finally:
150+
PIL.Image.MAX_IMAGE_PIXELS = original_pil_max_image_pixels
151+
143152
if len(image.shape) < 3:
144153
raise ValueError("not an RGB image")
145154

0 commit comments

Comments
 (0)