mirror of
https://github.com/apache/superset.git
synced 2026-04-18 23:55:00 +00:00
fix(dashboard): handle invalid thumbnail BytesIO objects gracefully (#35808)
Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
committed by
GitHub
parent
c3b8c96db6
commit
7c9720e22b
@@ -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",
|
||||
|
||||
Reference in New Issue
Block a user