diff options
-rw-r--r-- | src/core/SkRegion.cpp | 5 | ||||
-rw-r--r-- | tests/RegionTest.cpp | 23 |
2 files changed, 28 insertions, 0 deletions
diff --git a/src/core/SkRegion.cpp b/src/core/SkRegion.cpp index 8c402e9250..3a1a63e187 100644 --- a/src/core/SkRegion.cpp +++ b/src/core/SkRegion.cpp @@ -289,6 +289,11 @@ bool SkRegion::setRuns(RunType runs[], int count) { memcpy(fRunHead->writable_runs(), runs, count * sizeof(RunType)); fRunHead->computeRunBounds(&fBounds); + // Our computed bounds might be too large, so we have to check here. + if (fBounds.isEmpty()) { + return this->setEmpty(); + } + SkDEBUGCODE(this->validate();) return true; diff --git a/tests/RegionTest.cpp b/tests/RegionTest.cpp index 7fcf1014f7..be84d14c14 100644 --- a/tests/RegionTest.cpp +++ b/tests/RegionTest.cpp @@ -396,3 +396,26 @@ DEF_TEST(Region_readFromMemory_bad, r) { REPORTER_ASSERT(r, 0 == region.readFromMemory(data, sizeof(data))); } } + +DEF_TEST(region_toobig, reporter) { + const int big = 1 << 30; + const SkIRect neg = SkIRect::MakeXYWH(-big, -big, 10, 10); + const SkIRect pos = SkIRect::MakeXYWH( big, big, 10, 10); + + REPORTER_ASSERT(reporter, !neg.isEmpty()); + REPORTER_ASSERT(reporter, !pos.isEmpty()); + + SkRegion negR(neg); + SkRegion posR(pos); + + REPORTER_ASSERT(reporter, !negR.isEmpty()); + REPORTER_ASSERT(reporter, !posR.isEmpty()); + + SkRegion rgn; + rgn.op(negR, posR, SkRegion::kUnion_Op); + + // If we union those to rectangles, the resulting coordinates span more than int32_t, so + // we must mark the region as empty. + REPORTER_ASSERT(reporter, rgn.isEmpty()); +} + |