split-mixtral: grow tensors[] array instead of assert() (fixes heap OOB write)#32
Open
gigioneggiando wants to merge 1 commit into
Open
Conversation
The split-mixtral subcommand allocates a fixed tensors[] array of max_tensors (2048) entries and guards the per-tensor write only with assert(num_tensors < max_tensors). assert() is compiled out under -DNDEBUG (the usual release build), so a source model declaring more than 2048 tensors overflows the array with model-file-controlled data: a heap out-of-bounds write. Replace the assert with a real runtime check that doubles the array via realloc when it fills up, matching the existing malloc-failure handling (perror + exit). This both closes the overflow and lets a legitimate model with more than 2048 tensors be processed.
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.
Problem
The
split-mixtralsubcommand allocates a fixed-size array:The only bound on
tensors[num_tensors]isassert(), which is compiled out under-DNDEBUG(the usual release build). A source model that declares more than 2048 tensors then overflows the array with model-file-controlled data, a heap out-of-bounds write. The tensor count is read straight from the input.gguf, so this is attacker-controlled for any untrusted model.Reproduction
A crafted 2049-tensor
.gguffed to the realsplit-mixtralbinary, release build (-DNDEBUG) under AddressSanitizer:Fix
Replace the
assertwith a real runtime check that doubles the array viareallocwhen it fills, matching the existingmalloc-failure handling (perror+exit). This closes the overflow and, as a bonus, lets a legitimate model with more than 2048 tensors be processed instead of aborting.Verified with the same ASan build after the patch: all 2049 tensors are processed and written, no out-of-bounds write.
Part of a small local audit of the GGUF read path against untrusted model files. No CVE or public advisory from my side.