Commit 1f9e927
committed
Fix critical KV cache crash bug causing std::length_error
Resolves issue #771 where server crashes with std::length_error when
KV cache context shifting attempts to resize cache_tokens vector with
integer underflow.
The bug occurs in update_slots() when n_discard >= cache_tokens.size(),
causing cache_tokens.resize(size - n_discard) to underflow and request
massive memory allocation, triggering std::length_error exception.
Changes:
- Add bounds checking before cache_tokens.resize() in server.cpp:1714
- Clear cache_tokens when n_discard would cause underflow
- Prevent negative n_discard values from causing issues
This fix prevents production server crashes reported with Chinese text
translation workloads and high memory pressure scenarios.1 parent d4135d2 commit 1f9e927
File tree
3 files changed
+47
-1
lines changed- llama.cpp/server
3 files changed
+47
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1711 | 1711 | | |
1712 | 1712 | | |
1713 | 1713 | | |
1714 | | - | |
| 1714 | + | |
| 1715 | + | |
| 1716 | + | |
| 1717 | + | |
| 1718 | + | |
| 1719 | + | |
1715 | 1720 | | |
1716 | 1721 | | |
1717 | 1722 | | |
| |||
Binary file not shown.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
0 commit comments