Skip to content

Commit ca5e477

Browse files
committed
Check if argument is out-of-bounds in KernelBuilder::buffer_size
1 parent e25a11f commit ca5e477

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/builder.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,14 @@ KernelBuilder& KernelBuilder::buffer_size(ArgExpr arg, TypedExpr<size_t> len) {
180180
ArgsEval eval {args, fallback};
181181
size_t i = arg.get();
182182
size_t n = eval(len);
183+
184+
if (i >= args.size()) {
185+
throw std::runtime_error(
186+
"argument " + std::to_string(i)
187+
+ " is out of bounds for kernel that has only "
188+
+ std::to_string(args.size()) + " parameters");
189+
}
190+
183191
args[i] = args[i].to_array(n);
184192
});
185193
}
@@ -512,4 +520,4 @@ KernelInstance KernelBuilder::compile(
512520
std::move(assertions)};
513521
}
514522

515-
} // namespace kernel_launcher
523+
} // namespace kernel_launcher

0 commit comments

Comments
 (0)