Bound GGUF metadata/tensor counts by file size before allocating (DoS)#545
Open
gigioneggiando wants to merge 1 commit into
Open
Bound GGUF metadata/tensor counts by file size before allocating (DoS)#545gigioneggiando wants to merge 1 commit into
gigioneggiando wants to merge 1 commit into
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
parse_metadata()andparse_tensors()calloc()a table sized directly from the header-declaredm->n_kv/m->n_tensors, with no check against the mapped file. A 24-byte file declaringn_kv = 2^32makesparse_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 declaringn_kv = 2^32(ASan allocation cap on):calloc(n_kv, 32)= ~137 GB request atparse_metadata.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.