Skip to content

Commit 53acfe6

Browse files
committed
Add bounds check
1 parent e772b28 commit 53acfe6

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

ggml/src/ggml-cuda/ggml-cuda.cu

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2831,6 +2831,11 @@ static bool ggml_cuda_can_fuse(const struct ggml_cgraph * cgraph, int node_idx,
28312831
std::initializer_list<enum ggml_op> topk_moe_ops_with_norm = ggml_cuda_topk_moe_ops(true);
28322832

28332833
if (ops.size() == topk_moe_ops_with_norm.size() && std::equal(ops.begin(), ops.end(), topk_moe_ops_with_norm.begin())) {
2834+
2835+
if (node_idx + topk_moe_ops_with_norm.size() > (size_t)cgraph->n_nodes) {
2836+
return false;
2837+
}
2838+
28342839
for (size_t i = 0; i < topk_moe_ops_with_norm.size(); i++) {
28352840
if (cgraph->nodes[node_idx + i]->op != topk_moe_ops_with_norm.begin()[i]) return false;
28362841
}
@@ -2843,6 +2848,11 @@ static bool ggml_cuda_can_fuse(const struct ggml_cgraph * cgraph, int node_idx,
28432848
}
28442849

28452850
if (ops.size() == topk_moe_ops.size() && std::equal(ops.begin(), ops.end(), topk_moe_ops.begin())) {
2851+
2852+
if (node_idx + topk_moe_ops.size() > (size_t)cgraph->n_nodes) {
2853+
return false;
2854+
}
2855+
28462856
for (size_t i = 0; i < topk_moe_ops.size(); i++) {
28472857
if (cgraph->nodes[node_idx + i]->op != topk_moe_ops.begin()[i]) return false;
28482858
}

0 commit comments

Comments
 (0)