You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by el...@apache.org on 2025/10/24 18:38:42 UTC

(superset) branch master updated: fix(dashboard): handle invalid thumbnail BytesIO objects gracefully (#35808)

This is an automated email from the ASF dual-hosted git repository.

elizabeth pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/superset.git


The following commit(s) were added to refs/heads/master by this push:
     new 7c9720e22b fix(dashboard): handle invalid thumbnail BytesIO objects gracefully (#35808)
7c9720e22b is described below

commit 7c9720e22bbf17dfc65ab39a5768c6cf58433ef8
Author: Elizabeth Thompson <es...@gmail.com>
AuthorDate: Fri Oct 24 11:38:35 2025 -0700

    fix(dashboard): handle invalid thumbnail BytesIO objects gracefully (#35808)
    
    Co-authored-by: Claude <no...@anthropic.com>
---
 superset/dashboards/api.py | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

diff --git a/superset/dashboards/api.py b/superset/dashboards/api.py
index bf77d372d6..8f62d3f9af 100644
--- a/superset/dashboards/api.py
+++ b/superset/dashboards/api.py
@@ -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",