Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3045)

Unified Diff: cc/output/filter_operations_unittest.cc

Issue 2231243002: Use CheckedNumeric when converting SkIRect to gfx::Rect. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: handle the negative case; add more comments and unit tests Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | ui/gfx/skia_util.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: cc/output/filter_operations_unittest.cc
diff --git a/cc/output/filter_operations_unittest.cc b/cc/output/filter_operations_unittest.cc
index 4939dca83f13512a24efaf84bd1055dd342f27e9..54fb974452ab90e35272a03b06c4d92176393fa8 100644
--- a/cc/output/filter_operations_unittest.cc
+++ b/cc/output/filter_operations_unittest.cc
@@ -6,9 +6,11 @@
#include "cc/output/filter_operations.h"
#include "testing/gtest/include/gtest/gtest.h"
+#include "third_party/skia/include/core/SkXfermode.h"
#include "third_party/skia/include/effects/SkBlurImageFilter.h"
#include "third_party/skia/include/effects/SkDropShadowImageFilter.h"
#include "third_party/skia/include/effects/SkOffsetImageFilter.h"
+#include "third_party/skia/include/effects/SkXfermodeImageFilter.h"
#include "ui/gfx/geometry/point.h"
#include "ui/gfx/geometry/rect.h"
@@ -275,6 +277,23 @@ TEST(FilterOperationsTest, MapRectReverseDropShadowDoesNotContract) {
ops.MapRectReverse(gfx::Rect(0, 0, 10, 10), SkMatrix::I()));
}
+TEST(FilterOperationsTest, MapRectTypeConversionDoesNotOverflow) {
+ // Must be bigger than half of the positive range so that the width/height
+ // overflow happens, but small enough that there aren't other issues before
+ // the overflow would happen.
+ SkScalar big_offset =
+ SkFloatToScalar(std::numeric_limits<int>::max()) * 2 / 3;
+
+ FilterOperations ops;
+ ops.Append(FilterOperation::CreateReferenceFilter(SkXfermodeImageFilter::Make(
+ SkXfermode::Make(SkXfermode::kSrcOver_Mode),
+ SkOffsetImageFilter::Make(-big_offset, -big_offset, nullptr),
+ SkOffsetImageFilter::Make(big_offset, big_offset, nullptr), nullptr)));
+ gfx::Rect rect = ops.MapRect(gfx::Rect(-10, -10, 20, 20), SkMatrix::I());
+ EXPECT_GT(rect.width(), 0);
+ EXPECT_GT(rect.height(), 0);
+}
+
#define SAVE_RESTORE_AMOUNT(filter_name, filter_type, a) \
{ \
FilterOperation op = FilterOperation::Create##filter_name##Filter(a); \
« no previous file with comments | « no previous file | ui/gfx/skia_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698