neimasilk commited on
Commit
4042a56
·
verified ·
1 Parent(s): 4214295

Upload README.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +37 -0
README.md ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # llama.cpp Jinja2 Template Parser Stack Overflow PoC
2
+
3
+ ## Vulnerability
4
+ **Type:** Stack Overflow via Uncontrolled Recursion (CWE-674)
5
+ **Location:** `common/jinja/parser.cpp` — recursive descent parser with no depth limit
6
+ **Severity:** Medium (CVSS 5.5) — DoS via crafted GGUF model file
7
+ **Tested:** llama.cpp commit c5ce4bc (2026-04-08)
8
+
9
+ ## Root Cause
10
+ The Jinja2 template parser uses recursive descent with NO recursion depth limit.
11
+ A GGUF file with ~5,500+ levels of nested `{% if %}` blocks in `tokenizer.chat_template`
12
+ causes SIGSEGV (stack overflow) when any llama.cpp application loads the model.
13
+
14
+ ## Crash Output
15
+ ```
16
+ Depth 5000: Parser completed (OK)
17
+ Depth 5500: core dumped (SIGSEGV!)
18
+ Depth 10000: core dumped (SIGSEGV!)
19
+ ```
20
+
21
+ ## Files
22
+ - `poc_parser_stackoverflow.gguf` — Crafted GGUF with 50,000 nested if-blocks (~1.2 MB)
23
+ - `poc_recursive_macro.gguf` — Recursive macro that crashes at runtime (244 bytes)
24
+ - `poc_range_oom.gguf` — Unbounded range() causing OOM (203 bytes)
25
+ - `create_poc_jinja.py` — Generator script for all PoC variants
26
+
27
+ ## Reproduction
28
+ ```bash
29
+ # Build llama.cpp, then:
30
+ llama-server -m poc_parser_stackoverflow.gguf
31
+ # Result: Segmentation fault (core dumped)
32
+ ```
33
+
34
+ ## Suggested Fix
35
+ Add `MAX_PARSE_DEPTH` counter to recursive descent functions in parser.cpp.
36
+
37
+ **License:** MIT | **Researcher:** neimasilk | **Disclosure:** huntr.com