浏览代码

LibGfx: Make sure the Painter clip rect is never larger than the target

The new Painter::set_clip_rect(IntRect) API was able to make the clip
rect larger than the underlying target bitmap. This was not good, as it
could make it possible to draw outside the bitmap memory.

Fixes a crash when viewing https://twinings.co.uk/ in the browser. :^)
Andreas Kling 2 年之前
父节点
当前提交
e9078e216d
共有 2 个文件被更改,包括 6 次插入1 次删除
  1. 5 0
      Userland/Libraries/LibGfx/Painter.cpp
  2. 1 1
      Userland/Libraries/LibGfx/Painter.h

+ 5 - 0
Userland/Libraries/LibGfx/Painter.cpp

@@ -2575,4 +2575,9 @@ void Painter::draw_scaled_bitmap_with_transform(IntRect const& dst_rect, Bitmap
     }
     }
 }
 }
 
 
+void Painter::set_clip_rect(IntRect const& rect)
+{
+    state().clip_rect = rect.intersected(m_target->rect());
+}
+
 }
 }

+ 1 - 1
Userland/Libraries/LibGfx/Painter.h

@@ -177,7 +177,7 @@ public:
     }
     }
 
 
     IntRect clip_rect() const { return state().clip_rect; }
     IntRect clip_rect() const { return state().clip_rect; }
-    void set_clip_rect(IntRect const& rect) { state().clip_rect = rect; }
+    void set_clip_rect(IntRect const&);
 
 
     int scale() const { return state().scale; }
     int scale() const { return state().scale; }