Commit 64804798 authored by Khushal's avatar Khushal Committed by Commit Bot

cc: Try lower limits when allocating bitmaps for scrollbars.

Make fuzzers happy.

R=ericrk@chromium.org

Bug: 1001916
Change-Id: I7b0c32848f321171407b9e4fdf6d6cb5cfb0ca3f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1803959
Commit-Queue: Eric Karl <ericrk@chromium.org>
Reviewed-by: default avatarEric Karl <ericrk@chromium.org>
Auto-Submit: Khushal <khushalsagar@chromium.org>
Cr-Commit-Position: refs/heads/master@{#697406}
parent 51a08089
...@@ -11,10 +11,6 @@ ...@@ -11,10 +11,6 @@
#include "cc/trees/layer_tree_host.h" #include "cc/trees/layer_tree_host.h"
#include "third_party/skia/include/core/SkBitmap.h" #include "third_party/skia/include/core/SkBitmap.h"
namespace {
static constexpr int kMaxScrollbarDimension = 8192;
}
namespace cc { namespace cc {
std::unique_ptr<LayerImpl> PaintedScrollbarLayer::CreateLayerImpl( std::unique_ptr<LayerImpl> PaintedScrollbarLayer::CreateLayerImpl(
...@@ -239,13 +235,23 @@ UIResourceBitmap PaintedScrollbarLayer::RasterizeScrollbarPart( ...@@ -239,13 +235,23 @@ UIResourceBitmap PaintedScrollbarLayer::RasterizeScrollbarPart(
// Pages can end up requesting arbitrarily large scrollbars. Prevent this // Pages can end up requesting arbitrarily large scrollbars. Prevent this
// from crashing due to OOM and try something smaller. // from crashing due to OOM and try something smaller.
SkBitmap skbitmap; SkBitmap skbitmap;
if (!skbitmap.tryAllocN32Pixels(content_rect.width(), bool allocation_succeeded =
content_rect.height())) { skbitmap.tryAllocN32Pixels(content_rect.width(), content_rect.height());
content_rect.Intersect( // Assuming 4bpp, caps at 4M.
gfx::Rect(requested_content_rect.x(), requested_content_rect.y(), constexpr int kMinScrollbarDimension = 1024;
kMaxScrollbarDimension, kMaxScrollbarDimension)); int dimension = std::max(content_rect.width(), content_rect.height()) / 2;
skbitmap.allocN32Pixels(content_rect.width(), content_rect.height()); while (!allocation_succeeded && dimension >= kMinScrollbarDimension) {
content_rect.Intersect(gfx::Rect(requested_content_rect.x(),
requested_content_rect.y(), dimension,
dimension));
allocation_succeeded =
skbitmap.tryAllocN32Pixels(content_rect.width(), content_rect.height());
if (!allocation_succeeded)
dimension = dimension / 2;
} }
CHECK(allocation_succeeded)
<< "Failed to allocate memory for scrollbar at dimension : " << dimension;
SkiaPaintCanvas canvas(skbitmap); SkiaPaintCanvas canvas(skbitmap);
canvas.clear(SK_ColorTRANSPARENT); canvas.clear(SK_ColorTRANSPARENT);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment