Skip to content

gguf: reject malformed tensor dims, metadata keys, string lengths, and zero layer counts - #26946

Closed
voidwest wants to merge 1 commit into
ggml-org:masterfrom
voidwest:fix/gguf-malformed-input-validation
Closed

gguf: reject malformed tensor dims, metadata keys, string lengths, and zero layer counts#26946
voidwest wants to merge 1 commit into
ggml-org:masterfrom
voidwest:fix/gguf-malformed-input-validation

Conversation

@voidwest

@voidwest voidwest commented Aug 12, 2026

Copy link
Copy Markdown

Overview

gguf_init_from_file_impl dies with SIGFPE (integer division by zero,
no error message) when a GGUF tensor declares a zero dimension, e.g.
shape [4, 0]: the negative-dimension check passes, then
INT64_MAX / ne[1] divides by zero in the size-representability check.
A 96-byte file (header + one tensor info, dims [4, 0]) crashes the
process on load. This PR rejects non-positive dimensions with a
structured error.

Also verified against current master while preparing this PR: two
related findings from the same differential-fuzzing campaign are
already fixed upstream (empty metadata keys are rejected with an error;
declared string lengths are bounded by GGUF_MAX_STRING_LENGTH and the
remaining file bytes), and block_count = 0 now trips a clear
GGML_ASSERT(n_layer_all > 0) instead of the previous opaque abort.
This PR therefore contains only the zero-dimension fix, which remains
outstanding.

Repro: zero_dim (96 bytes): header + one tensor info (n_dims=2,
dims=[4,0], dtype=f32). Before: SIGFPE. After:
gguf_init_from_reader: tensor 't.weight' dimension 1 must be positive, got 0.

Additional information

Found by differential fuzzing of GGUF loaders (tiny inert reproducers;
crash/availability defect, no memory-safety claim). Also reproduced on
b5998/b5999/b7999. Reports archived at
https://github.com/voidwest/embersec-research (research/embersec/comparative/disclosure/).

Requirements

  • I have read and agree with the contributing guidelines
  • AI usage disclosure: YES - prepared with AI assistance under the
    direction of a human researcher; the human is responsible for all
    submitted changes.

@ggml-gh-bot

ggml-gh-bot Bot commented Aug 12, 2026

Copy link
Copy Markdown

Hi @voidwest, thanks for your contribution!

Per our contribution guidelines, the automated PR checker found the following issue(s) that need your attention:

  • PR Template not respected: Please respect the template when creating a new pull request. Make sure to fill out all required sections.

Please note that maintainers reserve the right to make final decisions on PRs. If you believe there is a mistake, please comment below.

@ggml-gh-bot ggml-gh-bot Bot added the draft PR will be changed to draft by github-actions bot label Aug 12, 2026
@github-actions
github-actions Bot marked this pull request as draft August 12, 2026 06:35
@github-actions github-actions Bot added ggml changes relating to the ggml tensor library for machine learning and removed draft PR will be changed to draft by github-actions bot labels Aug 12, 2026
A tensor with a zero dimension (e.g. shape [4, 0]) passes the existing
negative-dimension check and then divides by zero in the
size-representability check (INT64_MAX / ne[1] with ne[1] == 0),
killing the process with SIGFPE inside gguf_init_from_file_impl with no
error message. Reject non-positive dimensions with a structured error
(GGUF tensors must have positive dimensions; no compliant writer emits
zeros).

Verified: 96-byte reproducer (header + one tensor info, dims [4, 0])
now fails with "tensor 't.weight' dimension 1 must be positive, got 0"
instead of SIGFPE; valid models load unchanged.
@voidwest
voidwest force-pushed the fix/gguf-malformed-input-validation branch from ba7af6c to 7974054 Compare August 12, 2026 06:42
@CISC

CISC commented Aug 12, 2026

Copy link
Copy Markdown
Member

#24263
#20716
#25596
#26701

@CISC CISC closed this Aug 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ggml changes relating to the ggml tensor library for machine learning

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants