Skip to content

Commit 4cf5fd9

Browse files
Ethan NicholasSkia Commit-Bot
authored andcommitted
SkSL vector divide by zero now properly reports an error
Bug: oss-fuzz:14025 Change-Id: I45992c1953e054ce18c8e692273d44dc98f49fd8 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/220000 Reviewed-by: Brian Osman <brianosman@google.com> Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
1 parent 7206e38 commit 4cf5fd9

File tree

1 file changed

+19
-8
lines changed

1 file changed

+19
-8
lines changed

src/sksl/SkSLIRGenerator.cpp

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1572,13 +1572,13 @@ std::unique_ptr<Expression> IRGenerator::constantFold(const Expression& left,
15721572
if (left.fType.kind() == Type::kVector_Kind && left.fType.componentType().isFloat() &&
15731573
left.fType == right.fType) {
15741574
std::vector<std::unique_ptr<Expression>> args;
1575-
#define RETURN_VEC_COMPONENTWISE_RESULT(op) \
1576-
for (int i = 0; i < left.fType.columns(); i++) { \
1577-
float value = left.getFVecComponent(i) op \
1578-
right.getFVecComponent(i); \
1579-
args.emplace_back(new FloatLiteral(fContext, -1, value)); \
1580-
} \
1581-
return std::unique_ptr<Expression>(new Constructor(-1, left.fType, \
1575+
#define RETURN_VEC_COMPONENTWISE_RESULT(op) \
1576+
for (int i = 0; i < left.fType.columns(); i++) { \
1577+
float value = left.getFVecComponent(i) op \
1578+
right.getFVecComponent(i); \
1579+
args.emplace_back(new FloatLiteral(fContext, -1, value)); \
1580+
} \
1581+
return std::unique_ptr<Expression>(new Constructor(-1, left.fType, \
15821582
std::move(args)))
15831583
switch (op) {
15841584
case Token::EQEQ:
@@ -1590,7 +1590,18 @@ std::unique_ptr<Expression> IRGenerator::constantFold(const Expression& left,
15901590
case Token::PLUS: RETURN_VEC_COMPONENTWISE_RESULT(+);
15911591
case Token::MINUS: RETURN_VEC_COMPONENTWISE_RESULT(-);
15921592
case Token::STAR: RETURN_VEC_COMPONENTWISE_RESULT(*);
1593-
case Token::SLASH: RETURN_VEC_COMPONENTWISE_RESULT(/);
1593+
case Token::SLASH:
1594+
for (int i = 0; i < left.fType.columns(); i++) {
1595+
SKSL_FLOAT rvalue = right.getFVecComponent(i);
1596+
if (rvalue == 0.0) {
1597+
fErrors.error(right.fOffset, "division by zero");
1598+
return nullptr;
1599+
}
1600+
float value = left.getFVecComponent(i) / rvalue;
1601+
args.emplace_back(new FloatLiteral(fContext, -1, value));
1602+
}
1603+
return std::unique_ptr<Expression>(new Constructor(-1, left.fType,
1604+
std::move(args)));
15941605
default: return nullptr;
15951606
}
15961607
}

0 commit comments

Comments
 (0)