Skip to content

Bound GGUF metadata/tensor counts by file size before allocating (DoS)#545

Open
gigioneggiando wants to merge 1 commit into
antirez:mainfrom
gigioneggiando:fix/loader-count-dos
Open

Bound GGUF metadata/tensor counts by file size before allocating (DoS)#545
gigioneggiando wants to merge 1 commit into
antirez:mainfrom
gigioneggiando:fix/loader-count-dos

Conversation

@gigioneggiando

Copy link
Copy Markdown

Summary

parse_metadata() and parse_tensors() calloc() a table sized directly from the header-declared m->n_kv / m->n_tensors, with no check against the mapped file. A 24-byte file declaring n_kv = 2^32 makes parse_metadata() request ~137 GB up front — a load-time DoS/OOM from a tiny crafted model file.

Fix

Each metadata/tensor entry occupies at least one byte in the file, so a count larger than the bytes remaining (c->size - c->pos) cannot be real. Reject it before the allocation. Legitimate models are unaffected (their counts are far smaller than the file).

Verification

Drove the real parse_metadata() with a header declaring n_kv = 2^32 (ASan allocation cap on):

  • before: calloc(n_kv, 32) = ~137 GB request at parse_metadata.
  • after: ds4: GGUF metadata count exceeds file size, no large allocation.

Found during a coordinated security review of ds4; a standalone offline PoC is available on request.

parse_metadata() and parse_tensors() calloc() a table sized directly from
the header-declared m->n_kv / m->n_tensors, with no check against the
mapped file. A 24-byte file declaring n_kv = 2^32 makes parse_metadata()
request ~137 GB up front -- a load-time DoS from a tiny crafted model.

Each metadata/tensor entry occupies at least one byte in the file, so a
count larger than the bytes remaining (c->size - c->pos) cannot be real;
reject it before the allocation.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant