From 5b0fca4269bb2f23c23889ab6163f779694da55f Mon Sep 17 00:00:00 2001 From: Stella Laurenzo Date: Tue, 7 Nov 2023 16:29:01 -0800 Subject: [PATCH] Handle gguf zero-width types. (#15473) I don't know how these originate but this was encountered in a live weights file and was causing and FPE upon parsing. --- runtime/src/iree/io/formats/gguf/gguf_format.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/runtime/src/iree/io/formats/gguf/gguf_format.c b/runtime/src/iree/io/formats/gguf/gguf_format.c index 176b826d39c9..bae7435f79ad 100644 --- a/runtime/src/iree/io/formats/gguf/gguf_format.c +++ b/runtime/src/iree/io/formats/gguf/gguf_format.c @@ -322,6 +322,11 @@ static uint64_t iree_io_gguf_calculate_storage_size( element_count *= tensor_info->dimensions[i]; } const ggml_type_traits_t type_traits = ggml_type_traits[tensor_info->type]; + if (type_traits.type_size == 0) { + // For some reason some entries have a 0 type size and a 0 blck_size. + // Detect this to avoid FPE. + return 0; + } return (element_count * type_traits.type_size) / type_traits.blck_size; }