Skip to content

Commit 1da0fc5

Browse files
herbderbydahlstrom-g
authored andcommitted
Guard against overflow in blur code.
This fuzz creates a blur that has w = 1 and h = 2^31 - epsilon. And a filter sigma of 360. This causes the intermediate buffer size > 2^31. This causes the multiply in the following code SkMaskBlurFilter.cpp:1023: tmpStart + tmpW * tmpH to overflow. Because tmpW = source height, which is near 2^31, and tmpH is about 3*360. Cause the blur to fail if the intermediate buffer is > INT_MAX. (cherry picked from commit b70a030066b554b0fc7ba4c061449ac486a62283) Reviewed-on: https://skia-review.googlesource.com/c/skia/+/558305
1 parent 41a4df3 commit 1da0fc5

1 file changed

Lines changed: 15 additions & 11 deletions

File tree

‎third_party/skia/src/core/SkMask.cpp‎

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
#include "include/private/SkTo.h"
1212
#include "src/core/SkSafeMath.h"
1313

14+
#include <climits>
15+
1416
/** returns the product if it is positive and fits in 31 bits. Otherwise this
1517
returns 0.
1618
*/
@@ -57,27 +59,29 @@ SkMask SkMask::PrepareDestination(int radiusX, int radiusY, const SkMask& src) {
5759
SkSafeMath safe;
5860

5961
SkMask dst;
62+
dst.fImage = nullptr;
63+
dst.fFormat = SkMask::kA8_Format;
64+
6065
// dstW = srcW + 2 * radiusX;
6166
size_t dstW = safe.add(src.fBounds.width(), safe.add(radiusX, radiusX));
6267
// dstH = srcH + 2 * radiusY;
6368
size_t dstH = safe.add(src.fBounds.height(), safe.add(radiusY, radiusY));
6469

65-
if (!SkTFitsIn<int>(dstW) || !SkTFitsIn<int>(dstH)) {
70+
size_t toAlloc = safe.mul(dstW, dstH);
71+
72+
// We can only deal with masks that fit in INT_MAX and sides that fit in int.
73+
if (!SkTFitsIn<int>(dstW) || !SkTFitsIn<int>(dstH) || toAlloc > INT_MAX || !safe) {
6674
dst.fBounds.setEmpty();
6775
dst.fRowBytes = 0;
68-
} else {
69-
dst.fBounds.setWH(SkTo<int>(dstW), SkTo<int>(dstH));
70-
dst.fBounds.offset(src.fBounds.x(), src.fBounds.y());
71-
dst.fBounds.offset(-radiusX, -radiusY);
72-
dst.fRowBytes = SkTo<uint32_t>(dstW);
76+
return dst;
7377
}
7478

75-
dst.fImage = nullptr;
76-
dst.fFormat = SkMask::kA8_Format;
77-
78-
size_t toAlloc = safe.mul(dstW, dstH);
79+
dst.fBounds.setWH(SkTo<int>(dstW), SkTo<int>(dstH));
80+
dst.fBounds.offset(src.fBounds.x(), src.fBounds.y());
81+
dst.fBounds.offset(-radiusX, -radiusY);
82+
dst.fRowBytes = SkTo<uint32_t>(dstW);
7983

80-
if (safe && src.fImage != nullptr) {
84+
if (src.fImage != nullptr) {
8185
dst.fImage = SkMask::AllocImage(toAlloc);
8286
}
8387

0 commit comments

Comments
 (0)