diff options
author | herb <herb@google.com> | 2015-11-18 10:50:33 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-11-18 10:50:33 -0800 |
commit | 5520dede2968372e79c572e37b7f325524ee0739 (patch) | |
tree | c63deb631a82510472b98e89388be607b23348b6 /tests/BlitMaskClip.cpp | |
parent | 988adddd48322bfa3e3cb0c017cfce71fbbf1123 (diff) |
Fix buffer overrun, bit overrun and add a test.
BUG=539691
Review URL: https://codereview.chromium.org/1453163002
Diffstat (limited to 'tests/BlitMaskClip.cpp')
-rw-r--r-- | tests/BlitMaskClip.cpp | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/tests/BlitMaskClip.cpp b/tests/BlitMaskClip.cpp new file mode 100644 index 0000000000..a3bce1713d --- /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; + } +} |