Skip to content

Reject truncated GGUF tensor data in split and export tools - #30497

Merged
ggerganov merged 2 commits into
ggml-org:masterfrom
ppAlexa:fix/gguf-split-truncated-input
Oct 19, 2026
Merged

ggerganov merged 2 commits into
ggml-org:masterfrom
ppAlexa:fix/gguf-split-truncated-input

Conversation

@ppAlexa

@ppAlexa ppAlexa commented Oct 14, 2026

Copy link
Copy Markdown
Contributor

Overview

This change addresses incorrect tensor data handling when a GGUF file is truncated or its tensor data extends beyond the end of the file.

In gguf-split, the requested tensor data could be read incompletely without the short read being detected. Since the read buffer is reused, the remaining bytes could contain data from a previous tensor, resulting in corrupted output without the expected error.

The changes add bounds validation for tensor data in gguf-split and export-lora, along with checks to detect incomplete reads. A regression test creates a small GGUF file containing two tensors, truncates the file before the second tensor's data, and verifies that the tool rejects the input. It also checks that splitting the valid file preserves the expected tensor data.

Additional information

NA

Requirements

  • I have read and agree with the contributing guidelines
  • AI usage disclosure:YES
    AI assistance covered investigating the truncated-GGUF issue, analyzing the cause of the unchecked reads, proposing the bounds-check implementation, and developing the regression test.
    I applied the patch, built the affected tools, ran the regression tests, reviewed the Git diff, and submitted the changes.

…pted 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.#
@CISC

CISC commented Oct 14, 2026

Copy link
Copy Markdown
Member

Why the seeking when you can just check the state of the stream? Also, drop the tests please.

…e 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.
@ppAlexa

ppAlexa commented Oct 15, 2026

Copy link
Copy Markdown
Contributor Author

I have removed the seeking and the changes made in tests.sh while keeping the short-read checks by checking the stream state.

@CISC CISC added the merge ready A maintainer can use this label to indicate that they consider the changes final and ready to merge. label Oct 15, 2026
@ggerganov
ggerganov merged commit 8f97d82 into ggml-org:master Oct 19, 2026
13 checks passed
edwardyoon pushed a commit to edwardyoon/focus-llama that referenced this pull request Oct 24, 2026
…gml-org#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.
auRose94 pushed a commit to auRose94/llama.cpp that referenced this pull request Oct 28, 2026
…gml-org#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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

examples merge ready A maintainer can use this label to indicate that they consider the changes final and ready to merge.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants