resolver: Limit the number of parameters to 255

See: https://github.com/gpuweb/gpuweb/issues/1959

Fixed: chromium:1228642
Change-Id: Iadedd0a1396ebb6a006caa99e0931a92eb2c008e
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/58390
Commit-Queue: David Neto <dneto@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: David Neto <dneto@google.com>
This commit is contained in:
Ben Clayton 2021-07-17 17:45:25 +00:00 committed by Tint LUCI CQ
parent b85099ae73
commit 725159c17c
2 changed files with 27 additions and 0 deletions

View File

@ -644,6 +644,28 @@ TEST_F(ResolverFunctionValidationTest, ParameterSotreType_AtomicFree) {
EXPECT_TRUE(r()->Resolve()) << r()->error();
}
TEST_F(ResolverFunctionValidationTest, ParametersAtLimit) {
ast::VariableList params;
for (int i = 0; i < 255; i++) {
params.emplace_back(Param("param_" + std::to_string(i), ty.i32()));
}
Func(Source{{12, 34}}, "f", params, ty.void_(), {});
EXPECT_TRUE(r()->Resolve()) << r()->error();
}
TEST_F(ResolverFunctionValidationTest, ParametersOverLimit) {
ast::VariableList params;
for (int i = 0; i < 256; i++) {
params.emplace_back(Param("param_" + std::to_string(i), ty.i32()));
}
Func(Source{{12, 34}}, "f", params, ty.void_(), {});
EXPECT_FALSE(r()->Resolve());
EXPECT_EQ(r()->error(),
"12:34 error: functions may declare at most 255 parameters");
}
struct TestParams {
ast::StorageClass storage_class;
bool should_pass;

View File

@ -1388,6 +1388,11 @@ bool Resolver::ValidateFunction(const ast::Function* func,
}
}
if (func->params().size() > 255) {
AddError("functions may declare at most 255 parameters", func->source());
return false;
}
for (auto* param : func->params()) {
if (!ValidateFunctionParameter(func, variable_to_info_.at(param))) {
return false;