diff --git a/Libraries/LibWeb/Painting/BackgroundPainting.cpp b/Libraries/LibWeb/Painting/BackgroundPainting.cpp index 4faed6b75e2..e83955ac3ee 100644 --- a/Libraries/LibWeb/Painting/BackgroundPainting.cpp +++ b/Libraries/LibWeb/Painting/BackgroundPainting.cpp @@ -268,6 +268,12 @@ void paint_background(PaintContext& context, PaintableBox const& paintable_box, while (image_x < css_clip_rect.right()) { image_rect.set_x(image_x); auto image_device_rect = context.rounded_device_rect(image_rect); + // If the image's dimensions were rounded to zero then they need to be restored to avoid a crash. + // There's no need to check that !image_rect.is_empty() because empty images are discarded in resolve_background_layers. + if (image_device_rect.width() == 0) + image_device_rect.set_width(1); + if (image_device_rect.height() == 0) + image_device_rect.set_height(1); callback(image_device_rect); if (!repeat_x) break; @@ -299,6 +305,13 @@ void paint_background(PaintContext& context, PaintableBox const& paintable_box, // Use a dedicated painting command for repeated images instead of recording a separate command for each instance // of a repeated background, so the painter has the opportunity to optimize the painting of repeated images. auto dest_rect = context.rounded_device_rect(image_rect); + // If the image's dimensions were rounded to zero then they need to be restored to avoid a crash. + // There's no need to check that !image_rect.is_empty() because empty images are discarded in resolve_background_layers. + if (dest_rect.width() == 0) + dest_rect.set_width(1); + if (dest_rect.height() == 0) + dest_rect.set_height(1); + auto const* bitmap = static_cast(image).current_frame_bitmap(dest_rect); auto scaling_mode = to_gfx_scaling_mode(image_rendering, bitmap->rect(), dest_rect.to_type()); context.display_list_recorder().draw_repeated_immutable_bitmap(dest_rect.to_type(), clip_rect.to_type(), *bitmap, scaling_mode, { .x = repeat_x, .y = repeat_y }); diff --git a/Tests/LibWeb/Ref/data/50x50-green.svg b/Tests/LibWeb/Ref/data/50x50-green.svg new file mode 100644 index 00000000000..21af545019d --- /dev/null +++ b/Tests/LibWeb/Ref/data/50x50-green.svg @@ -0,0 +1,3 @@ + + + diff --git a/Tests/LibWeb/Ref/expected/background-size-near-zero-svg-ref.html b/Tests/LibWeb/Ref/expected/background-size-near-zero-svg-ref.html new file mode 100644 index 00000000000..ebd2d860cec --- /dev/null +++ b/Tests/LibWeb/Ref/expected/background-size-near-zero-svg-ref.html @@ -0,0 +1,2 @@ + +
diff --git a/Tests/LibWeb/Ref/input/background-size-near-zero-svg.html b/Tests/LibWeb/Ref/input/background-size-near-zero-svg.html new file mode 100644 index 00000000000..892ae0f97ea --- /dev/null +++ b/Tests/LibWeb/Ref/input/background-size-near-zero-svg.html @@ -0,0 +1,7 @@ + + +
+
+ +