llama : check LoRA tensor data is within file bounds - #27056
Merged
Conversation
CISC
reviewed
Aug 14, 2026
Co-authored-by: Sigbjørn Skjæret <sigbjorn.skjaeret@huggingface.co>
CISC
approved these changes
Aug 14, 2026
Member
|
@oakkaya Try to remember to use our PR template though. |
Contributor
Author
Updated the description to follow the template, thanks. |
CowboyTim
pushed a commit
to aardbeiplantje/llama.cpp
that referenced
this pull request
Aug 16, 2026
* llama : check LoRA tensor data is within file bounds * Update src/llama-adapter.cpp Co-authored-by: Sigbjørn Skjæret <sigbjorn.skjaeret@huggingface.co> --------- Co-authored-by: Sigbjørn Skjæret <sigbjorn.skjaeret@huggingface.co>
Hundsbuah
added a commit
to Hundsbuah/llama.cpp
that referenced
this pull request
Aug 16, 2026
This source tree is based on the uploaded `ggml-org/llama.cpp` master snapshot corresponding to commit: - `10bf611e533d81f739128304991c5e133c6aebd8` — `llama : check LoRA tensor data is within file bounds (ggml-org#27056)` The reasoning-budget feature was ported from: - `ggml-org/llama.cpp` PR ggml-org#25961 - `laurencehardman/llama-mindcontrol` - reviewed fork sync commit `dc2845e3fbb607a2ae0cfc366c5ad647eb145d79` (2026-07-31) Merge performed: 2026-08-16. ## Integrated behavior - Explicit master switch: `--reasoning-budget-enable` / `--no-reasoning-budget-enable`. - Hard reasoning token budget. - Optional intro sequence with `{budget}` substitution. - Optional soft warning at a configurable consumed-budget ratio. - Optional bounded grace period after hard-budget exhaustion. - Runtime `reasoning_end` control when explicitly armed. - Custom hard-cutoff message semantics from PR ggml-org#25961: a non-empty hard message is tokenized exactly as supplied and therefore must contain the model/template closing tag; an empty hard message falls back to the first detected closing tag. - Prefill replay fix: fixed prompt tokens no longer consume positions in a just-activated forced intro/soft/hard sequence. - Multiple valid reasoning start/end sequences and end-match tracking from current upstream. - UTF-8-safe hard cutoff behavior from current upstream. - Re-arming for multiple reasoning blocks in one response. ## Conflict resolutions against the newer master The PR was not copied file-for-file. It was re-layered over the current master so newer upstream behavior is retained. 1. The current Aho-Corasick multi-pattern reasoning-tag matcher is retained. 2. The current sampler interface, including `backend_reset` and `copy_state`, is retained. 3. The PR's INTRO/SOFT/HARD_PENDING states are integrated on top of the newer upstream state machine. 4. The master switch remains authoritative even when `grammar_lazy` independently requires the reasoning tracker. In tracking-only mode, intro/soft/grace/hard-budget control values are neutralized. 5. `reasoning_control` without a finite budget can still arm runtime hard-stop control, but does not accidentally activate intro/soft/grace behavior with an unlimited (`-1`) budget. 6. The runtime `reasoning_end` endpoint now checks both the global master switch and the per-request arm flag, and reports whether the live sampler was actually in a forceable state. 7. The older hard-budget initializer signature remains available as a compatibility overload for current-upstream callers/tests. 8. Generated CLI/completion/server option tables were regenerated with the current `llama-gen-docs`; older generated documentation was not copied over current master documentation. 9. The upstream root `README.md` is preserved. The fork-specific root README/benchmark narrative is not allowed to overwrite current llama.cpp project documentation; this file records the port instead. ## Validation performed Environment used for validation: - Linux x86_64 - CMake 3.31.6 - GCC/G++ 14.2.0 Verified locally: - `test-reasoning-budget` builds successfully. - 22 test functions pass, covering the current upstream cases plus PR conflict/regression paths; the consolidated manual-force test checks all four extended active states. - UTF-8 boundary tests pass. - `llama-server` compiles and links successfully against the merged sources. - `llama-server --help` exposes the new reasoning-budget flags and environment-variable names. - `llama-gen-docs` builds and regenerates the CLI/completion/server reference tables. - `git diff --check` passes. The build environment had no DNS access to download the optional embedded llama-server Web UI asset. llama.cpp therefore built the server without an embedded UI; this did not affect compilation/linking of the server or reasoning-budget source paths. ## Not validated here - CUDA compilation was not available in the validation container. - Model-specific end-to-end generation quality was not tested because no target GGUF/model was supplied for this merge step. - The PR remains experimental/draft upstream; successful source integration and unit/build validation do not establish that the injected intro/soft messages improve quality for every model/template. ## Relevant options ```text --reasoning-budget-enable --no-reasoning-budget-enable --reasoning-budget N --reasoning-budget-message MESSAGE --reasoning-budget-soft-ratio N --reasoning-budget-soft-message MESSAGE --reasoning-budget-intro-message MESSAGE --reasoning-budget-grace-tokens N ``` Corresponding environment variables: ```text LLAMA_ARG_THINK_BUDGET_ENABLE LLAMA_ARG_THINK_BUDGET LLAMA_ARG_THINK_BUDGET_MESSAGE LLAMA_ARG_THINK_BUDGET_SOFT_RATIO LLAMA_ARG_THINK_BUDGET_SOFT_MESSAGE LLAMA_ARG_THINK_BUDGET_INTRO_MESSAGE LLAMA_ARG_THINK_BUDGET_GRACE_TOKENS ```
4 tasks
brittlewis12
pushed a commit
to brittlewis12/llama.cpp
that referenced
this pull request
Aug 17, 2026
* llama : check LoRA tensor data is within file bounds * Update src/llama-adapter.cpp Co-authored-by: Sigbjørn Skjæret <sigbjorn.skjaeret@huggingface.co> --------- Co-authored-by: Sigbjørn Skjæret <sigbjorn.skjaeret@huggingface.co>
4 tasks
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.
Overview
The LoRA adapter loading path reads tensor data without checking that
the tensor offset + size falls within the file bounds. A truncated or
corrupted LoRA file is silently loaded with zero-padded weights and no
error is reported.
The main model loader already performs this check
(src/llama-model-loader.h), so the LoRA path is the only place where
the missing validation can lead to silent data corruption.
This change:
Additional information
Tested with a truncated LoRA file (data section cut short): the loader
now fails with "tensor data is not within the file bounds" instead of
silently loading partial data. A valid LoRA file loads without errors.
Requirements