Skip to content

Commit

Permalink
gguf : prevent integer overflow
Browse files Browse the repository at this point in the history
  • Loading branch information
ggerganov committed Jan 29, 2024
1 parent 81584d9 commit 78fd95e
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions src/ggml.c
Original file line number Diff line number Diff line change
Expand Up @@ -19348,10 +19348,9 @@ struct gguf_context * gguf_init_from_file(const char * fname, struct gguf_init_p
}

// sanity-checks to prevent from integer/buffer overflows
// - sizeof(struct gguf_tensor_info)*n_tensors < SIZE_MAX
// - sizeof(struct gguf_kv)*n_kv < SIZE_MAX

ok = ok && (ctx->header.n_tensors < SIZE_MAX/sizeof(struct gguf_tensor_info));
ok = ok && (ctx->header.n_tensors < SIZE_MAX/ggml_tensor_overhead());
ok = ok && (ctx->header.n_kv < SIZE_MAX/sizeof(struct gguf_kv));

if (!ok) {
Expand Down

0 comments on commit 78fd95e

Please sign in to comment.