Skip to content

[201_72] 修复导言区调用未定义颜色变量导致软件崩溃#2753

Merged
MoonL79 merged 3 commits intoMoganLab:mainfrom
notfoundzzz:201_72
Feb 5, 2026
Merged

[201_72] 修复导言区调用未定义颜色变量导致软件崩溃#2753
MoonL79 merged 3 commits intoMoganLab:mainfrom
notfoundzzz:201_72

Conversation

@notfoundzzz
Copy link
Contributor

@notfoundzzz notfoundzzz commented Feb 4, 2026

如何测试

  1. 打开 TeXmacs/tests/tmu/201_72.tmu 文件
  2. Ctrl+Shift+p进入导言区
  3. 鼠标光标移动到backcolor后回车应该不会导致软件闪退问题

2026/2/4

What

  1. src/Graphics/Renderer/brush.cppmake_brush(tree p, int a) 中增加非法 pattern 输入校验,遇到异常复合树时回退为 no_brush
  2. src/Graphics/Renderer/brush.cppget_pattern_data(...) 中增加结构和 URL 健壮性检查,非法输入回退到安全默认值,避免继续解包。

Why

关联issue #2745
<value|backcolor> 在变量未定义时会产生异常值,该值进入颜色渲染链路后被误当作 pattern 解包。
MuPDF 路径中会继续读取非法 pattern 图像信息(日志可见 bad image size for '{}'),最终触发 SIGSEGV。

@da-liii da-liii added the bug Something isn't working label Feb 4, 2026
@MoonL79 MoonL79 requested a review from Copilot February 5, 2026 02:07
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a crash that occurs when undefined color variables are referenced in the document preamble. When a variable like backcolor is undefined, it produces an abnormal value that gets incorrectly interpreted as a pattern and causes a segmentation fault during rendering.

Changes:

  • Added defensive validation in make_brush() to reject invalid composite trees before treating them as patterns
  • Added structure and URL validation in get_pattern_data() to safely handle invalid patterns with fallback to default values
  • Added test file and documentation for the fix

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
src/Graphics/Renderer/brush.cpp Added validation checks to prevent crashes from invalid pattern structures
devel/201_72.md Documentation explaining the fix and testing instructions
TeXmacs/tests/tmu/201_72.tmu Test case with undefined color variable to verify the fix

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

// 防御性处理:非法复合树(例如未定义变量展开后的 UNINIT)
// 不能当作 pattern 继续解包,否则后续访问 pattern[1]/pattern[2] 可能崩溃。
if (N (p) != 4 || !is_atomic (p[0])) return tm_new<no_brush_rep> ();
if (as_string (p[0]) == "" || as_string (p[0]) == "{}")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

通过 LABEL来看

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

L(p)

}

static brush_rep*
make_brush (tree p, int a) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

增加注释,说明p和a都是什么

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doxygen风格

@MoonL79 MoonL79 merged commit a089a5d into MoganLab:main Feb 5, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants