diff --git a/src/launchpad/size/insights/apple/image_optimization.py b/src/launchpad/size/insights/apple/image_optimization.py index 8d8aa833..bac28191 100644 --- a/src/launchpad/size/insights/apple/image_optimization.py +++ b/src/launchpad/size/insights/apple/image_optimization.py @@ -12,7 +12,7 @@ import pillow_heif # type: ignore -from PIL import Image, ImageFile +from PIL import Image, ImageFile, UnidentifiedImageError from launchpad.size.insights.insight import Insight, InsightsInput from launchpad.size.models.apple import AppleAppInfo @@ -121,6 +121,10 @@ def _analyze_image_optimization( logger.info("Skipping %s because it has no full path", file_info.path) return None + if file_info.size == 0: + logger.info("Skipping %s because it is empty (0 bytes)", file_info.path) + return None + try: with Image.open(file_info.full_path) as img: img.load() # type: ignore @@ -159,6 +163,9 @@ def _analyze_image_optimization( idiom=file_info.idiom, colorspace=file_info.colorspace, ) + except UnidentifiedImageError: + logger.warning("Skipping %s: cannot identify image format", file_info.path) + return None except Exception: logger.exception("Failed to open or process image file") return None