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. :^)
This commit is contained in:
Andreas Kling 2023-02-10 22:10:36 +01:00
parent b4596b48f5
commit e9078e216d
2 changed files with 6 additions and 1 deletions

View file

@ -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());
}
}

View file

@ -177,7 +177,7 @@ public:
}
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; }