Skip to content

Truly independent web browser

Compositor: Stop sharing image surfaces too large for a GPU texture

Andreas Klingf9dfa79ff6c3
diff --git a/Services/Compositor/SkiaUtils.cpp b/Services/Compositor/SkiaUtils.cpp
index a8267857233..1fa928f83b7 100644
--- a/Services/Compositor/SkiaUtils.cpp
+++ b/Services/Compositor/SkiaUtils.cpp
@@ -492,6 +492,10 @@ sk_sp<SkImage> sk_texture_image_sharing_pixels_of_decoded_image_frame([[maybe_un
auto* gr_context = skia_backend_context.sk_context();
if (!iosurface || !gr_context)
return nullptr;
+ // NB: Metal aborts when asked for a texture larger than the GPU supports, so such a frame is drawn from its pixels
+ // in memory instead.
+ if (frame.width() > gr_context->maxTextureSize() || frame.height() > gr_context->maxTextureSize())
+ return nullptr;
auto texture_format = first_is_one_of(frame.format(), BitmapFormat::RGBA8888, BitmapFormat::RGBx8888) ? MetalTextureFormat::RGBA8 : MetalTextureFormat::BGRA8;
// The frame's surface may come from another process, which need not have aligned its rows as the GPU needs them,
diff --git a/Tests/LibWeb/Crash/Painting/image-wider-than-max-texture-size.html b/Tests/LibWeb/Crash/Painting/image-wider-than-max-texture-size.html
new file mode 100644
index 00000000000..fdd85c36fc1
--- /dev/null
+++ b/Tests/LibWeb/Crash/Painting/image-wider-than-max-texture-size.html
@@ -0,0 +1,3 @@
+<!DOCTYPE html>
+<!-- The image is 61500 pixels wide, wider than the largest texture a GPU allows. -->
+<img src="image-wider-than-max-texture-size.png" style="width: 600px; height: 40px">
diff --git a/Tests/LibWeb/Crash/Painting/image-wider-than-max-texture-size.png b/Tests/LibWeb/Crash/Painting/image-wider-than-max-texture-size.png
new file mode 100644
index 00000000000..c70409c68b2
Binary files /dev/null and b/Tests/LibWeb/Crash/Painting/image-wider-than-max-texture-size.png differ