Преглед на файлове

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; }