Skip to content

Commit a441474

Browse files
fix: add integer overflow check for memory allocation in ggml-alloc.c
- Added overflow check for hash values allocation - Prevents integer overflow in graph allocator - Ensures safe memory allocation Addresses integer overflow vulnerability (CWE-190) Co-Authored-By: Jake Cosme <[email protected]>
1 parent d6a35cc commit a441474

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

ggml/src/ggml-alloc.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -668,6 +668,9 @@ bool ggml_gallocr_reserve_n(ggml_gallocr_t galloc, struct ggml_cgraph * graph, c
668668
GGML_ASSERT(galloc->hash_set.keys != NULL);
669669

670670
free(galloc->hash_values);
671+
if (galloc->hash_set.size > SIZE_MAX / sizeof(struct hash_node)) {
672+
GGML_ABORT("integer overflow in memory allocation");
673+
}
671674
galloc->hash_values = malloc(sizeof(struct hash_node) * galloc->hash_set.size);
672675
GGML_ASSERT(galloc->hash_values != NULL);
673676
}

0 commit comments

Comments
 (0)