Truly independent web browser
Compositor: Don't abort when a repeated tile can't be allocated
Shannon Booth650c1cd95ea2
diff --git a/Services/Compositor/DisplayListPlayerSkia.cpp b/Services/Compositor/DisplayListPlayerSkia.cppindex 2e0c316eb4a..123fa8f82bd 100644--- a/Services/Compositor/DisplayListPlayerSkia.cpp+++ b/Services/Compositor/DisplayListPlayerSkia.cpp@@ -633,7 +633,11 @@ void DisplayListPlayerSkia::play_command(DrawRepeatedTile const& command)sk_sp<SkImage> DisplayListPlayerSkia::rasterize_records_into_tile(ReadonlyBytes tile_records, Gfx::IntRect tile_rect){- auto tile_surface = Gfx::PaintingSurface::create_with_size(tile_rect.size(), Gfx::BitmapFormat::BGRA8888, Gfx::AlphaType::Premultiplied, m_skia_backend_context);+ // NB: A tile can be larger than any surface, e.g. a background tile far wider than a bitmap can be.+ auto tile_surface_or_error = Gfx::PaintingSurface::try_create_with_size(tile_rect.size(), Gfx::BitmapFormat::BGRA8888, Gfx::AlphaType::Premultiplied, m_skia_backend_context);+ if (tile_surface_or_error.is_error())+ return nullptr;+ auto tile_surface = tile_surface_or_error.release_value();tile_surface->canvas().clear(SK_ColorTRANSPARENT);tile_surface->canvas().translate(-tile_rect.x(), -tile_rect.y());execute_command_bytes_into_surface(tile_records, *tile_surface);@@ -1374,8 +1378,12 @@ void DisplayListPlayerSkia::play_command(PaintNestedDisplayList const& command)auto raster_candidate_rect = rasterize_whole_list ? list_bounds : visible_rect_in_list_space;if (byte_size(raster_candidate_rect) <= max_raster_bytes) {cached_image = raster_cache().create_nested_display_list_raster(command.display_list_id, m_skia_backend_context, raster_candidate_rect, [&] {- auto offscreen_surface = Gfx::PaintingSurface::create_with_size(+ // NB: When the raster can't be allocated, the nested list is replayed directly instead.+ auto offscreen_surface_or_error = Gfx::PaintingSurface::try_create_with_size(raster_candidate_rect.size(), Gfx::BitmapFormat::BGRA8888, Gfx::AlphaType::Premultiplied, m_skia_backend_context);+ if (offscreen_surface_or_error.is_error())+ return sk_sp<SkImage> {};+ auto offscreen_surface = offscreen_surface_or_error.release_value();offscreen_surface->canvas().clear(SK_ColorTRANSPARENT);offscreen_surface->canvas().translate(-raster_candidate_rect.x(), -raster_candidate_rect.y());execute_display_list_into_surface(diff --git a/Tests/LibWeb/Crash/CSS/background-tile-wider-than-a-bitmap-can-be.html b/Tests/LibWeb/Crash/CSS/background-tile-wider-than-a-bitmap-can-be.htmlnew file mode 100644index 00000000000..41df3439aaa--- /dev/null+++ b/Tests/LibWeb/Crash/CSS/background-tile-wider-than-a-bitmap-can-be.html@@ -0,0 +1,9 @@+<!DOCTYPE html>+<!-- Repeated background tiles wider than a bitmap can be must not crash the compositor. -->+<style>+ div { width: 400px; height: 400px; background-repeat: repeat; background-size: 70000px 1px; }+ .svg { background-image: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' width='10' height='10'><rect width='10' height='10' fill='green'/></svg>"); }+ .gradient { height: 4000px; background-image: linear-gradient(to right, red, blue); }+</style>+<div class="svg"></div>+<div class="gradient"></div>