Skip to content

Commit dbbbe0c

Browse files
JohannesGaesslerggerganov
authored andcommitted
gguf: fix failure on version == 0 (llama/13956)
1 parent 3a9ce1f commit dbbbe0c

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

src/gguf.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -347,25 +347,28 @@ struct gguf_context * gguf_init_from_file_impl(FILE * file, struct gguf_init_par
347347
int64_t n_tensors = 0;
348348

349349
if (ok && gr.read(ctx->version)) {
350+
if (ok && ctx->version == 0) {
351+
GGML_LOG_ERROR("%s: bad GGUF version: %" PRIu32 "\n", __func__, ctx->version);
352+
ok = false;
353+
}
354+
350355
/*
351356
* bit layout is different when reading non-native endian models.
352357
* assuming that the GGUF version is 3, the non-native endian model
353358
* would read it as 0x30000000. we can use the AND operation against
354359
* the last 4 hexadecimal digits to check if the model is the same
355360
* endianness as the host system.
356361
*/
357-
if ((ctx->version & 0x0000FFFF) == 0x00000000) {
362+
if (ok && (ctx->version & 0x0000FFFF) == 0x00000000) {
358363
GGML_LOG_ERROR("%s: failed to load model: this GGUF file version %" PRIu32 " is extremely large, is there a mismatch between the host and model endianness?\n", __func__, ctx->version);
359-
gguf_free(ctx);
360-
return nullptr;
364+
ok = false;
361365
}
362366

363-
GGML_ASSERT(ctx->version > 0 && ctx->version <= 65535);
364-
if (ctx->version == 1) {
367+
if (ok && ctx->version == 1) {
365368
GGML_LOG_ERROR("%s: GGUFv1 is no longer supported, please use a more up-to-date version\n", __func__);
366369
ok = false;
367370
}
368-
if (ctx->version > GGUF_VERSION) {
371+
if (ok && ctx->version > GGUF_VERSION) {
369372
GGML_LOG_ERROR("%s: this GGUF file is version %" PRIu32 " but this software only supports up to version %d\n",
370373
__func__, ctx->version, GGUF_VERSION);
371374
ok = false;

0 commit comments

Comments
 (0)