Skip to content

llama : check LoRA tensor data is within file bounds - #27056

Merged
ggerganov merged 2 commits into
ggml-org:masterfrom
oakkaya:fix/lora-bounds-check
Aug 16, 2026
Merged

llama : check LoRA tensor data is within file bounds#27056
ggerganov merged 2 commits into
ggml-org:masterfrom
oakkaya:fix/lora-bounds-check

Conversation

@oakkaya

@oakkaya oakkaya commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

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:

  • mirrors the existing bounds check from llama-model-loader.h
  • also validates that the tensor index is found in the file

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

  • I have read and agree with the contributing guidelines
  • AI usage disclosure: YES - AI was used to draft parts of the code changes; all changes were reviewed and verified by me.

@oakkaya
oakkaya requested a review from CISC as a code owner August 14, 2026 09:17
Comment thread src/llama-adapter.cpp Outdated
Co-authored-by: Sigbjørn Skjæret <sigbjorn.skjaeret@huggingface.co>
@CISC CISC added the merge ready A maintainer can use this label to indicate that they consider the changes final and ready to merge. label Aug 14, 2026
@CISC

CISC commented Aug 14, 2026

Copy link
Copy Markdown
Member

@oakkaya Try to remember to use our PR template though.

@oakkaya

oakkaya commented Aug 14, 2026

Copy link
Copy Markdown
Contributor Author

@oakkaya Try to remember to use our PR template though.

Updated the description to follow the template, thanks.

@ggerganov
ggerganov merged commit 10bf611 into ggml-org:master Aug 16, 2026
27 of 28 checks passed
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>
@oakkaya
oakkaya deleted the fix/lora-bounds-check branch August 16, 2026 13:44
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
```
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge ready A maintainer can use this label to indicate that they consider the changes final and ready to merge.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants