aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/BitmapTest.cpp
diff options
context:
space:
mode:
authorGravatar reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-12-30 19:21:22 +0000
committerGravatar reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-12-30 19:21:22 +0000
commit4856964eae9cdb779baa08ef9e5646ccb9a3140d (patch)
tree7d78a0cfbb31c8635932529f69f548349f0c8429 /tests/BitmapTest.cpp
parent51c2a83bdac0745fc3b60795401d5db29c10ce11 (diff)
ComputeRowBytes must not overflow width when it shifts
BUG= R=halcanary@google.com Review URL: https://codereview.chromium.org/122473002 git-svn-id: http://skia.googlecode.com/svn/trunk@12848 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'tests/BitmapTest.cpp')
-rw-r--r--tests/BitmapTest.cpp18
1 files changed, 18 insertions, 0 deletions
diff --git a/tests/BitmapTest.cpp b/tests/BitmapTest.cpp
index 250b6da32c..aaa297e674 100644
--- a/tests/BitmapTest.cpp
+++ b/tests/BitmapTest.cpp
@@ -10,6 +10,22 @@
#include "Test.h"
#include "TestClassDef.h"
+static void test_bigwidth(skiatest::Reporter* reporter) {
+ SkBitmap bm;
+ int width = 1 << 29; // *4 will be the high-bit of 32bit int
+
+ REPORTER_ASSERT(reporter, bm.setConfig(SkBitmap::kA8_Config, width, 1));
+ REPORTER_ASSERT(reporter, bm.setConfig(SkBitmap::kRGB_565_Config, width, 1));
+
+ // for a 4-byte config, this width will compute a rowbytes of 0x80000000,
+ // which does not fit in a int32_t. setConfig should detect this, and fail.
+
+ // TODO: perhaps skia can relax this, and only require that rowBytes fit
+ // in a uint32_t (or larger), but for now this is the constraint.
+
+ REPORTER_ASSERT(reporter, !bm.setConfig(SkBitmap::kARGB_8888_Config, width, 1));
+}
+
/**
* This test contains basic sanity checks concerning bitmaps.
*/
@@ -27,4 +43,6 @@ DEF_TEST(Bitmap, reporter) {
REPORTER_ASSERT(reporter, SkToBool(width & height) != bm.empty());
}
}
+
+ test_bigwidth(reporter);
}