Skip to content

Commit 1ab01a0

Browse files
fix: add integer overflow check for calloc in ggml_build_backward_expand
- Added overflow check before calloc operation - Prevents integer overflow in gradient computation - Ensures safe memory allocation for grads_needed array Addresses integer overflow vulnerability (CWE-190) Co-Authored-By: Jake Cosme <[email protected]>
1 parent aefd843 commit 1ab01a0

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

ggml/src/ggml.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6386,6 +6386,10 @@ void ggml_build_backward_expand(
63866386

63876387
memset(cgraph->grads, 0, cgraph->visited_hash_set.size*sizeof(struct ggml_tensor *));
63886388
memset(cgraph->grad_accs, 0, cgraph->visited_hash_set.size*sizeof(struct ggml_tensor *));
6389+
6390+
if (cgraph->visited_hash_set.size > SIZE_MAX / sizeof(bool)) {
6391+
GGML_ABORT("integer overflow in memory allocation");
6392+
}
63896393
bool * grads_needed = calloc(cgraph->visited_hash_set.size, sizeof(bool));
63906394

63916395
{

0 commit comments

Comments
 (0)