From 7790a9231d85b8af26e87ee60d8ed7373f9713f0 Mon Sep 17 00:00:00 2001 From: Shreya Date: Sun, 25 Oct 2026 14:55:10 +0530 Subject: [PATCH] tools : reject truncated GGUF tensor data in merge (#31044) Co-authored-by: Shreya Agrawal --- tools/gguf-split/gguf-split.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tools/gguf-split/gguf-split.cpp b/tools/gguf-split/gguf-split.cpp index 173455938..73587b9fc 100644 --- a/tools/gguf-split/gguf-split.cpp +++ b/tools/gguf-split/gguf-split.cpp @@ -553,6 +553,10 @@ static void gguf_merge(const split_params & split_params) { auto offset = gguf_get_data_offset(ctx_gguf) + gguf_get_tensor_offset(ctx_gguf, i_tensor); f_input.seekg(offset); f_input.read((char *)read_data.data(), n_bytes); + if (!f_input) { + fprintf(stderr, "%s: failed to read %zu bytes at offset %zu, input file may be truncated\n", __func__, n_bytes, offset); + exit(EXIT_FAILURE); + } if (!split_params.dry_run) { // write tensor data + padding fout.write((const char *)read_data.data(), n_bytes);