Merged
Conversation
Contributor
There was a problem hiding this comment.
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.
MoonL79
approved these changes
Feb 5, 2026
da-liii
reviewed
Feb 5, 2026
| // 防御性处理:非法复合树(例如未定义变量展开后的 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]) == "{}") |
da-liii
reviewed
Feb 5, 2026
| } | ||
|
|
||
| static brush_rep* | ||
| make_brush (tree p, int a) { |
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.
如何测试
Ctrl+Shift+p进入导言区backcolor后回车应该不会导致软件闪退问题2026/2/4
What
src/Graphics/Renderer/brush.cpp的make_brush(tree p, int a)中增加非法 pattern 输入校验,遇到异常复合树时回退为no_brush。src/Graphics/Renderer/brush.cpp的get_pattern_data(...)中增加结构和 URL 健壮性检查,非法输入回退到安全默认值,避免继续解包。Why
关联issue #2745
<value|backcolor>在变量未定义时会产生异常值,该值进入颜色渲染链路后被误当作 pattern 解包。MuPDF 路径中会继续读取非法 pattern 图像信息(日志可见
bad image size for '{}'),最终触发 SIGSEGV。