Skip to content

Commit c3ca2aa

Browse files
ggerganovarthw
authored andcommitted
gguf : handle null name during init (ggml-org#8587)
1 parent 4b895a5 commit c3ca2aa

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

examples/gguf/gguf.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,11 @@ static bool gguf_ex_read_0(const std::string & fname) {
9292

9393
struct gguf_context * ctx = gguf_init_from_file(fname.c_str(), params);
9494

95+
if (!ctx) {
96+
fprintf(stderr, "%s: failed to load '%s'\n", __func__, fname.c_str());
97+
return false;
98+
}
99+
95100
printf("%s: version: %d\n", __func__, gguf_get_version(ctx));
96101
printf("%s: alignment: %zu\n", __func__, gguf_get_alignment(ctx));
97102
printf("%s: data offset: %zu\n", __func__, gguf_get_data_offset(ctx));

ggml/src/ggml.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21015,7 +21015,7 @@ struct gguf_context * gguf_init_from_file(const char * fname, struct gguf_init_p
2101521015
gguf_tensor_info_sanitize(info);
2101621016

2101721017
// make sure there is no duplicated tensor names
21018-
for (uint64_t j = 0; j < i; ++j) {
21018+
for (uint64_t j = 0; j < i && ok; ++j) {
2101921019
if (strcmp(info->name.data, ctx->infos[j].name.data) == 0) {
2102021020
fprintf(stderr, "%s: duplicated tensor name %s\n", __func__, info->name.data);
2102121021
ok = false;

0 commit comments

Comments
 (0)