mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-30 04:39:06 +00:00
LibWeb: Add missing empty size check before allocating PaintingSurface
Fixes crashing when Gfx::PaintingSurface::create_with_size() is called with a size of 0.
This commit is contained in:
parent
bd93285811
commit
fd25fea3ab
Notes:
github-actions[bot]
2024-12-05 16:21:51 +00:00
Author: https://github.com/kalenikaliaksandr
Commit: fd25fea3ab
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/2788
3 changed files with 14 additions and 2 deletions
|
@ -282,7 +282,7 @@ String HTMLCanvasElement::to_data_url(StringView type, JS::Value quality)
|
||||||
allocate_painting_surface_if_needed();
|
allocate_painting_surface_if_needed();
|
||||||
auto surface = this->surface();
|
auto surface = this->surface();
|
||||||
auto size = bitmap_size_for_canvas();
|
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
|
// 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();
|
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);
|
surface = Gfx::PaintingSurface::create_with_size(skia_backend_context, size, Gfx::BitmapFormat::BGRA8888, Gfx::AlphaType::Premultiplied);
|
||||||
|
@ -322,7 +322,7 @@ WebIDL::ExceptionOr<void> HTMLCanvasElement::to_blob(GC::Ref<WebIDL::CallbackTyp
|
||||||
allocate_painting_surface_if_needed();
|
allocate_painting_surface_if_needed();
|
||||||
auto surface = this->surface();
|
auto surface = this->surface();
|
||||||
auto size = bitmap_size_for_canvas();
|
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
|
// 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();
|
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);
|
surface = Gfx::PaintingSurface::create_with_size(skia_backend_context, size, Gfx::BitmapFormat::BGRA8888, Gfx::AlphaType::Premultiplied);
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
PASS (didn't crash!)
|
|
@ -0,0 +1,11 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<script src="../include.js"></script>
|
||||||
|
<script>
|
||||||
|
test(() => {
|
||||||
|
let c = document.createElement("canvas");
|
||||||
|
c.width = 300;
|
||||||
|
c.height = 0;
|
||||||
|
c.toDataURL();
|
||||||
|
println("PASS (didn't crash!)");
|
||||||
|
});
|
||||||
|
</script>
|
Loading…
Add table
Add a link
Reference in a new issue