tools : reject truncated GGUF tensor data in split and export tools (#30497)

* The problem here in the repo is gguf-split can silently produce corrupted tensor output when the input GGUF file is truncated. The fix is to add tensor-data bounds checks and short-read checks in gguf-split.cpp and export-lora.cpp, and a regression test that checks truncated input is rejected and valid tensor data is preserved.#

* Bug : GGUF-split can silently produce corrupted tensor output when the input GGUF file is truncated. Fix : add short-read checks in gguf-split.cpp (in copy_file_to_file in split_strategy) and export-lora.cpp (in read_tensor_data of file_input) so that truncated input is rejected.
This commit is contained in:
ppAlexa authored and GitHub committed 2026-10-19 09:27:46 +03:00
1 parent 27af58168a
commit 8f97d82da3
2 files changed
+7

No files matched your search

+3
View File
@@ -104,6 +104,9 @@ struct file_input {
auto offset = gguf_get_data_offset(ctx_gguf) + gguf_get_tensor_offset(ctx_gguf, i_tensor_in);
f_in.seekg(offset);
f_in.read((char* )buf.data(), len);
if (!f_in) {
throw std::runtime_error("failed to read data for tensor " + name + ", input file may be truncated");
}
}
~file_input() {
+4
View File
@@ -362,6 +362,10 @@ struct split_strategy {
}
f_in.seekg(in_offset);
f_in.read((char *)read_buf.data(), len);
if (!f_in) {
fprintf(stderr, "%s: failed to read %zu bytes at offset %zu, input file may be truncated\n", __func__, len, in_offset);
exit(EXIT_FAILURE);
}
f_out.write((const char *)read_buf.data(), len);
}
};