diff --git a/Libraries/LibWeb/HTML/HTMLCanvasElement.cpp b/Libraries/LibWeb/HTML/HTMLCanvasElement.cpp index 8a93fcab335..05e9cb80bcf 100644 --- a/Libraries/LibWeb/HTML/HTMLCanvasElement.cpp +++ b/Libraries/LibWeb/HTML/HTMLCanvasElement.cpp @@ -282,7 +282,7 @@ String HTMLCanvasElement::to_data_url(StringView type, JS::Value quality) allocate_painting_surface_if_needed(); auto surface = this->surface(); auto size = bitmap_size_for_canvas(); - if (!surface) { + if (!surface && !size.is_empty()) { // If the context is not initialized yet, we need to allocate transparent surface for serialization auto skia_backend_context = navigable()->traversable_navigable()->skia_backend_context(); surface = Gfx::PaintingSurface::create_with_size(skia_backend_context, size, Gfx::BitmapFormat::BGRA8888, Gfx::AlphaType::Premultiplied); @@ -322,7 +322,7 @@ WebIDL::ExceptionOr HTMLCanvasElement::to_blob(GC::Refsurface(); auto size = bitmap_size_for_canvas(); - if (!surface) { + if (!surface && !size.is_empty()) { // If the context is not initialized yet, we need to allocate transparent surface for serialization auto skia_backend_context = navigable()->traversable_navigable()->skia_backend_context(); surface = Gfx::PaintingSurface::create_with_size(skia_backend_context, size, Gfx::BitmapFormat::BGRA8888, Gfx::AlphaType::Premultiplied); diff --git a/Tests/LibWeb/Text/expected/canvas/fill-0-height-canvas-should-not-crash.txt b/Tests/LibWeb/Text/expected/canvas/fill-0-height-canvas-should-not-crash.txt new file mode 100644 index 00000000000..da17eba72e1 --- /dev/null +++ b/Tests/LibWeb/Text/expected/canvas/fill-0-height-canvas-should-not-crash.txt @@ -0,0 +1 @@ +PASS (didn't crash!) diff --git a/Tests/LibWeb/Text/input/canvas/fill-0-height-canvas-should-not-crash.html b/Tests/LibWeb/Text/input/canvas/fill-0-height-canvas-should-not-crash.html new file mode 100644 index 00000000000..a6e507a7ecb --- /dev/null +++ b/Tests/LibWeb/Text/input/canvas/fill-0-height-canvas-should-not-crash.html @@ -0,0 +1,11 @@ + + +