fix(search): reject parentheses nested deeper than 64 levels

Deep nesting overflowed the stack of the recursive Pidgin parser (around
400-700 levels), an uncatchable crash. The depth is now checked on the token
stream before parsing and reported as a syntax error. Listed in PLAN 6.2 and
USAGE.
This commit is contained in:
doyaGu committed 2026-10-03 08:12:34 -04:00
1 parent 8ae9780c0e
commit d2a5d36bd2
5 files changed
+70 -2

No files matched your search

+1
View File
@@ -291,6 +291,7 @@ phrase := '"' 任意文本 '"' (内部支持转义:\" → 字面引号,
- 短语内部转义:`\"` → 字面引号,`\\` → 字面反斜杠;搜索含空格/保留字符/字面 `AND` 等特殊标签名时,用(必要时转义的)引号值(写入文档)
- **严格校验**:非法表达式弹出错误对话框,不执行搜索。非法集合:
- 括号不配对
- 括号嵌套超过 64 层(防止递归解析栈溢出;顺序并列的括号组不计入深度)
- 运算符悬空(`bug AND`)、连续运算符(`a AND OR b`)
- 限定符无值(`tag:`)、限定符值为裸 `AND`/`OR`(`tag:AND`,须写 `tag:"AND"`)
- 短语引号未闭合、无效转义(`tag:"a\x"`)、裸词中出现 `\`