Index: src/core/SkPictureShader.cpp |
diff --git a/src/core/SkPictureShader.cpp b/src/core/SkPictureShader.cpp |
index 2a6aae5f4ed477db2daf3c781d6d98c1ada11851..65a2cd322291d2236754e3c965a81738d17aac1a 100644 |
--- a/src/core/SkPictureShader.cpp |
+++ b/src/core/SkPictureShader.cpp |
@@ -76,12 +76,21 @@ SkShader* SkPictureShader::refBitmapShader(const SkMatrix& matrix, const SkMatri |
} |
SkSize scaledSize = SkSize::Make(scale.x() * fTile.width(), scale.y() * fTile.height()); |
+ // Clamp the tile size to about 16M pixels |
+ static const SkScalar kMaxTileArea = 4096 * 4096; |
+ SkScalar tileArea = SkScalarMul(scaledSize.width(), scaledSize.height()); |
+ if (tileArea > kMaxTileArea) { |
+ SkScalar clampScale = SkScalarSqrt(SkScalarDiv(kMaxTileArea, tileArea)); |
+ scaledSize.set(SkScalarMul(scaledSize.width(), clampScale), |
+ SkScalarMul(scaledSize.height(), clampScale)); |
+ } |
+ |
SkISize tileSize = scaledSize.toRound(); |
if (tileSize.isEmpty()) { |
return NULL; |
} |
- // The actual scale, compensating for rounding. |
+ // The actual scale, compensating for rounding & clamping. |
SkSize tileScale = SkSize::Make(SkIntToScalar(tileSize.width()) / fTile.width(), |
SkIntToScalar(tileSize.height()) / fTile.height()); |