Skip to content

Commit 8f03ebe

Browse files
fix: add overflow check for calloc operation in clip_log_internal_v
Co-Authored-By: Jake Cosme <[email protected]>
1 parent e81d813 commit 8f03ebe

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

tools/mtmd/clip-impl.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,13 @@ static void clip_log_internal_v(enum ggml_log_level level, const char * format,
218218
if (len < 128) {
219219
g_logger_state.log_callback(level, buffer, g_logger_state.log_callback_user_data);
220220
} else {
221+
if (len < 0 || len >= INT_MAX) {
222+
return; // Invalid length from vsnprintf
223+
}
221224
char * buffer2 = (char *) calloc(len + 1, sizeof(char));
225+
if (!buffer2) {
226+
return; // Allocation failed
227+
}
222228
vsnprintf(buffer2, len + 1, format, args_copy);
223229
buffer2[len] = 0;
224230
g_logger_state.log_callback(level, buffer2, g_logger_state.log_callback_user_data);

0 commit comments

Comments
 (0)