Skip to content

Commit

Permalink
Canvas2d: Fix clusterfuzz crash
Browse files Browse the repository at this point in the history
It's caused due to divide by zero during calculating region's position.

Bug: 795604
Change-Id: Ibb1f43c6dea64549b9ca8e568d6dace4420fdf91
Reviewed-on: https://chromium-review.googlesource.com/893238
Reviewed-by: Justin Novosad <junov@chromium.org>
Commit-Queue: Jinho Bang <jinho.bang@samsung.com>
Cr-Commit-Position: refs/heads/master@{#538487}
  • Loading branch information
romandev authored and Commit Bot committed Feb 22, 2018
1 parent 44f67e8 commit 2c1d42f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
var paddingLeft = parseInt(canvas.style.paddingLeft) || 0;
var borderLeft = parseInt(canvas.style.borderLeft) || 0;
var cssWidth = parseInt(canvas.style.width) || canvas.width;
var scale = cssWidth / canvas.width;
var scale = canvas.width == 0 ? 1 : cssWidth / canvas.width;
var tx = x;
if (degree) {
var cos = Math.cos(degree * Math.PI / 180);
Expand All @@ -41,7 +41,7 @@
var paddingTop = parseInt(canvas.style.paddingTop) || 0;
var borderTop = parseInt(canvas.style.borderTop) || 0;
var cssHeight = parseInt(canvas.style.height) || canvas.height;
var scale = cssHeight / canvas.height;
var scale = canvas.height == 0 ? 1 : cssHeight / canvas.height;
var ty = y;
if (degree) {
var cos = Math.cos(degree * Math.PI / 180);
Expand Down Expand Up @@ -131,6 +131,15 @@
canvas.style.transform = 'rotate(72deg)';
yield hit_region_with_css_test(test_set_with_rotate);

canvas.width = '0';
canvas.height = '0';
canvas.style.width = "0px";
canvas.style.height = "0px";
var test_divide_zero = [
{ id : null, x : 20, y : 10, name: 'null' }
];
yield hit_region_with_css_test(test_divide_zero);

done();
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -654,8 +654,13 @@ HitTestCanvasResult* CanvasRenderingContext2D::GetControlAndIdIfHitRegionExists(
box->AbsoluteToLocal(FloatPoint(location), kUseTransforms);
if (box->HasBorderOrPadding())
local_pos.Move(-box->ContentBoxOffset());
local_pos.Scale(canvas()->width() / box->ContentWidth(),
canvas()->height() / box->ContentHeight());
float scaleWidth = box->ContentWidth().ToFloat() == 0.0f
? 1.0f
: canvas()->width() / box->ContentWidth();
float scaleHeight = box->ContentHeight().ToFloat() == 0.0f
? 1.0f
: canvas()->height() / box->ContentHeight();
local_pos.Scale(scaleWidth, scaleHeight);

HitRegion* hit_region = HitRegionAtPoint(local_pos);
if (hit_region) {
Expand Down

0 comments on commit 2c1d42f

Please sign in to comment.