From 10bf611e533d81f739128304991c5e133c6aebd8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?O=C4=9Fuzhan=20Akkaya?= Date: Sun, 16 Aug 2026 02:38:01 -0400 Subject: [PATCH] llama : check LoRA tensor data is within file bounds (#27056) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * llama : check LoRA tensor data is within file bounds * Update src/llama-adapter.cpp Co-authored-by: Sigbjørn Skjæret --------- Co-authored-by: Sigbjørn Skjæret --- src/llama-adapter.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/llama-adapter.cpp b/src/llama-adapter.cpp index 3e0fe66af..e6678a66d 100644 --- a/src/llama-adapter.cpp +++ b/src/llama-adapter.cpp @@ -396,8 +396,11 @@ static void llama_adapter_lora_init_impl(llama_model & model, const char * path_ llama_file gguf_file(path_lora, "rb"); std::vector read_buf; auto set_tensor = [&](ggml_tensor * orig, ggml_tensor * dev) { - size_t offs = gguf_get_data_offset(ctx_gguf.get()) + gguf_get_tensor_offset(ctx_gguf.get(), gguf_find_tensor(ctx_gguf.get(), orig->name)); - size_t size = ggml_nbytes(orig); + const size_t offs = gguf_get_data_offset(ctx_gguf.get()) + gguf_get_tensor_offset(ctx_gguf.get(), gguf_find_tensor(ctx_gguf.get(), orig->name)); + const size_t size = ggml_nbytes(orig); + if (offs + size < offs || offs + size > gguf_file.size()) { + throw std::runtime_error(format("LoRA tensor '%s' data is not within the file bounds, file is corrupted or incomplete", orig->name)); + } read_buf.resize(size); gguf_file.seek(offs, SEEK_SET); gguf_file.read_raw(read_buf.data(), size);