fix(dashboard): handle invalid thumbnail BytesIO objects gracefully (#35808)

Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
Elizabeth Thompson
2025-10-24 11:38:35 -07:00
committed by GitHub
parent c3b8c96db6
commit 7c9720e22b

View File

@@ -1342,10 +1342,32 @@ class DashboardRestApi(BaseSupersetModelRestApi):
self.incr_stats("from_cache", self.thumbnail.__name__)
try:
image = cache_payload.get_image()
# Validate the BytesIO object is properly initialized
if not image or not hasattr(image, "read"):
logger.warning(
"Thumbnail image object is invalid for dashboard %s",
str(dashboard.id),
)
return self.response_404()
# Additional validation: ensure the BytesIO has content
if image.getbuffer().nbytes == 0:
logger.warning(
"Thumbnail image is empty for dashboard %s",
str(dashboard.id),
)
return self.response_404()
# Reset position to ensure reading from start
image.seek(0)
except ScreenshotImageNotAvailableException:
return self.response_404()
except Exception as ex: # pylint: disable=broad-except
logger.error(
"Error retrieving thumbnail for dashboard %s: %s",
str(dashboard.id),
str(ex),
exc_info=True,
)
return self.response_404()
return Response(
FileWrapper(image),
mimetype="image/png",