[1294] 修复自递归/循环宏 LaTeX 粘贴导致进程崩溃(用例 249/289/pattern_c) - #4535
Merged
Conversation
Co-Authored-By: Claude <noreply@anthropic.com>
- latex_to_tree 入口兜底捕获底层字体解析抛出的 string 异常, 降级返回空文档,避免异常穿过 scheme 边界终止进程 - find_font 增加递归深度上限,规则成环时按未找到降级,防止栈溢出 Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Claude <noreply@anthropic.com>
- concat_macro.cpp: max_macro_depth 提升为文件级常量,两处超限检查收敛为 concater_rep::macro_depth_exceeded(消除 typeset_auto 静默不降级的漂移) - find_font.cpp: 手写计数+try/catch 回退改为 RAII find_font_guard, 与 macro_depth_guard 同构 - fromtex_post.cpp: tree_calls_macro 删除被子节点递归覆盖的 COMPOUND/APPLY 特判及 per-node as_string 标签比较 - parsetex_test.cpp: 三个用例收敛为 check_crash_case helper,删除空的 cleanupTestCase - 删除根目录重复的 1294.py,保留 TeXmacs/tests/python/ 下的规范位置副本 Co-Authored-By: Claude <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
问题
LaTeX 宏递归崩溃用例:
1294_1.tex): 无参自递归宏\def\crashMacro24{\crashMacro24} \crashMacro241294_2.tex): 带参自递归宏\def\paramRec28#1{\paramRec28{#1}#1} \paramRec28{x}1294_3.tex): 相互递归宏\newcommand{\macroA}{\macroB} \newcommand{\macroB}{\macroA} \macroAGUI「编辑 → 粘贴自 → LaTeX」后进程崩溃退出(SIGSEGV 栈溢出或未捕获异常终止进程)。
根因
递归宏会被转换解析为带有引用环路的宏定义。
在文档被插入或排版时,
concater_rep::typeset_compound展开宏体,遇到递归宏无展开深度限制,调用栈超过 47,000+ 帧直至栈溢出(SIGSEGV)。缺 TeX 字体时
load_tex抛出string异常穿过 scheme 边界导致进程终止;find_font规则成环导致栈溢出。改动
src/Typeset/env.hpp&src/Typeset/Env/env.cpp:edit_env增加macro_depth深度计数。src/Typeset/Concat/concat_macro.cpp:macro_depth_guard限制宏展开深度(上限 100),超限降级占位 box,杜绝无限递归死循环。src/Plugins/Tex/fromtex_post.cpp:has_macro_cycle拓扑成环检测,检测到递归宏定义时直接丢弃并警告返回空文档,避免向用户文档插入死循环内容;入口兜底捕获异常。src/Graphics/Fonts/find_font.cpp:find_font增加递归深度上限。tests/Plugins/Tex/parsetex_test.cpp:C++ 回归测试,覆盖用例 249、289、1294_3。TeXmacs/tests/tex/1294_{1,2,3}.tex:三个复现用例样本落盘。1294.py/TeXmacs/tests/python/1294.py:自动化 GUI 回归测试脚本。devel/1294.md:任务文档更新。测试
xmake b parsetex_test && xmake r parsetex_test:5 passedpython3 1294.py:1294_1.tex、1294_2.tex、1294_3.tex 均 PASSxmake r 0620&xmake r 0631:通过