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

Unified Diff: tests/BlitMaskClip.cpp

Issue 1453163002: Fix array overrun and add test. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: had x and y swapped Created 5 years, 1 month 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 | « src/core/SkBlitter.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/BlitMaskClip.cpp
diff --git a/tests/BlitMaskClip.cpp b/tests/BlitMaskClip.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..a3bce1713db47d687b7e508ae90a995da7f9c329
--- /dev/null
+++ b/tests/BlitMaskClip.cpp
@@ -0,0 +1,65 @@
+/*
+ * Copyright 2015 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "SkBlitter.h"
+#include "SkMask.h"
+#include "Test.h"
+
+class TestBlitter : public SkBlitter {
+public:
+ TestBlitter(SkIRect bounds, skiatest::Reporter* reporter)
+ : fBounds(bounds)
+ , fReporter(reporter) { }
+
+ void blitH(int x, int y, int width) override {
+
+ REPORTER_ASSERT(fReporter, x >= fBounds.fLeft && x < fBounds.fRight);
+ REPORTER_ASSERT(fReporter, y >= fBounds.fTop && y < fBounds.fBottom);
+ int right = x + width;
+ REPORTER_ASSERT(fReporter, right > fBounds.fLeft && right <= fBounds.fRight);
+ }
+
+private:
+ SkIRect fBounds;
+ skiatest::Reporter* fReporter;
+};
+
+
+// Exercise all clips compared with different widths of bitMask. Make sure that no buffer
+// overruns happen.
+DEF_TEST(BlitAndClip, reporter) {
+ const int originX = 100;
+ const int originY = 100;
+ for (int width = 1; width <= 32; width++) {
+ const int height = 2;
+ int rowBytes = (width + 7) >> 3;
+ uint8_t* bits = new uint8_t[rowBytes * height];
+
+ SkIRect b = {originX, originY, originX + width, originY + height};
+
+ SkMask mask;
+ mask.fFormat = SkMask::kBW_Format;
+ mask.fBounds = b;
+ mask.fImage = (uint8_t*)bits;
+ mask.fRowBytes = rowBytes;
+
+ TestBlitter tb(mask.fBounds, reporter);
+
+ for (int top = b.fTop; top < b.fBottom; top++) {
+ for (int bottom = top + 1; bottom <= b.fBottom; bottom++) {
+ for (int left = b.fLeft; left < b.fRight; left++) {
+ for (int right = left + 1; right <= b.fRight; right++) {
+ SkIRect clipRect = {left, top, right, bottom};
+ tb.blitMask(mask, clipRect);
+ }
+ }
+ }
+ }
+
+ delete [] bits;
+ }
+}
« no previous file with comments | « src/core/SkBlitter.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698