Repository navigation
fix: preserve GGUF metadata at buffer boundaries - #2458
Open
remote-controlled-man wants to merge 1 commit into
Open
remote-controlled-man wants to merge 1 commit into
remote-controlled-man wants to merge 1 commit into
Conversation
This branch has not been deployed
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.
Fix metadata reads that exactly fill the current native buffer.
The llama.cpp metadata APIs return the string length without the terminating NUL byte. The Python wrapper only resized for lengths greater than the buffer capacity, so a key or value of exactly that capacity lost its final byte. A truncated UTF-8 character caused
Llamato discard all metadata and fall back to the wrong chat format; a truncated Jinja comment could make an otherwise valid model fail to load.Resize for lengths greater than or equal to the capacity in both key and value reads. Add 17 regressions using actual GGUF files and the native loader: ASCII/UTF-8 keys and values at 1023/1024/1025 bytes, chat-template selection, and a value exactly filling a buffer enlarged by a longer key. No binding or vendor changes.
Validation:
stories15M-q4_0.ggufwith inserted metadata reproduces the load failure at a 1024-byte chat template and the UTF-8 metadata fallback. After the fix, all four end-to-end cases load, retain their metadata and usechat_template.default; the same chat request has 4 prompt tokens and identical greedy output. The UTF-8 fallback previously usedllama-2, 15 prompt tokens and different output.make test: 43 passed, no skips, on the final commit.make lint: Ruff checks passed; all 30 Python files pass the formatting check.git diff --check: passed.Environment: macOS arm64, Python 3.12.14, bundled llama.cpp
f5e6915c2, existing native build; end-to-end model runs usen_gpu_layers=0and fixed inputs.