Catch SkRuntimeEffects w/o "main" earlier
Previously, these would produce a "valid" effect object, but it wouldn't draw anything. Bug: oss-fuzz:24070 Change-Id: I17d0ed1710196853da0694cac9f4c260312700a9 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/304064 Commit-Queue: Brian Osman <brianosman@google.com> Reviewed-by: John Stiles <johnstiles@google.com>
This commit is contained in:
parent
6d0ab954e9
commit
182c92ebb3
@ -120,6 +120,7 @@ SkRuntimeEffect::EffectResult SkRuntimeEffect::Make(SkString sksl) {
|
||||
}
|
||||
SkASSERT(!compiler->errorCount());
|
||||
|
||||
bool hasMain = false;
|
||||
bool mainHasSampleCoords = SkSL::Analysis::ReferencesSampleCoords(*program);
|
||||
|
||||
std::vector<const SkSL::Variable*> inVars;
|
||||
@ -133,7 +134,7 @@ SkRuntimeEffect::EffectResult SkRuntimeEffect::Make(SkString sksl) {
|
||||
for (const auto& elem : *program) {
|
||||
// Variables (in, uniform, varying, etc.)
|
||||
if (elem.fKind == SkSL::ProgramElement::kVar_Kind) {
|
||||
const SkSL::VarDeclarations& varDecls = static_cast<const SkSL::VarDeclarations&>(elem);
|
||||
const auto& varDecls = static_cast<const SkSL::VarDeclarations&>(elem);
|
||||
for (const auto& varDecl : varDecls.fVars) {
|
||||
const SkSL::Variable& var =
|
||||
*(static_cast<const SkSL::VarDeclaration&>(*varDecl).fVar);
|
||||
@ -159,6 +160,18 @@ SkRuntimeEffect::EffectResult SkRuntimeEffect::Make(SkString sksl) {
|
||||
}
|
||||
}
|
||||
}
|
||||
// Functions
|
||||
else if (elem.fKind == SkSL::ProgramElement::kFunction_Kind) {
|
||||
const auto& func = static_cast<const SkSL::FunctionDefinition&>(elem);
|
||||
const SkSL::FunctionDeclaration& decl = func.fDeclaration;
|
||||
if (decl.fName == "main") {
|
||||
hasMain = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!hasMain) {
|
||||
RETURN_FAILURE("missing 'main' function");
|
||||
}
|
||||
|
||||
size_t offset = 0, uniformSize = 0;
|
||||
|
@ -56,6 +56,9 @@ DEF_TEST(SkRuntimeEffectInvalid, r) {
|
||||
test("layout(marker=local_to_world) uniform float3x3 localToWorld;", "", "float4x4");
|
||||
|
||||
test("half missing();", "color.r = missing();", "undefined function");
|
||||
|
||||
// Shouldn't be possible to create an SkRuntimeEffect without "main"
|
||||
test("//", "", "main");
|
||||
}
|
||||
|
||||
class TestEffect {
|
||||
|
Loading…
Reference in New Issue
Block a user