fix: guard against invalid color primaries to prevent crash on VMs / ICC-less displays - #1901
Open
loliri wants to merge 1 commit into
Open
fix: guard against invalid color primaries to prevent crash on VMs / ICC-less displays#1901loliri wants to merge 1 commit into
loliri wants to merge 1 commit into
Conversation
…ICC-less displays On VMs or devices without an ICC profile, DisplayAdvancedColorInfo can report NaN or out-of-range primaries. Feeding these to ICCHelper/lcms2 corrupts the GC heap and crashes (0xC0000005) when saving the screenshot. Fall back to BT709 when primaries are non-finite, outside (0,1), or violate the x+y<=1 CIE constraint. No behavior change for normal displays.
loliri
force-pushed
the
fix/screenshot-color-primaries-guard
branch
from
July 25, 2026 12:31
bc15ca2 to
628bba6
Compare
Contributor
There was a problem hiding this comment.
Pull request overview
This PR hardens screenshot color-management by validating display-reported color primaries (or ICC-derived primaries) before they are used downstream, preventing crashes on VMs / ICC-less or otherwise misreporting displays.
Changes:
- Validate
DisplayAdvancedColorInfo-reported primaries when no ICC profile is available; fallback to BT.709 if invalid. - Validate ICC-derived primaries from
ICCHelper; fallback to BT.709 if invalid. - Add
ArePrimariesValidhelper enforcing finiteness, (0,1) bounds, and CIE x+y≤1 constraint.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+196
to
+200
| private static bool ArePrimariesValid(ColorPrimaries p) | ||
| { | ||
| return Valid(p.Red) && Valid(p.Green) && Valid(p.Blue) && Valid(p.White); | ||
| static bool Valid(Vector2 v) => float.IsFinite(v.X) && float.IsFinite(v.Y) && v.X > 0f && v.X < 1f && v.Y > 0f && v.Y < 1f && v.X + v.Y <= 1f; | ||
| } |
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.
问题
VM 或无 ICC profile 的设备上,
DisplayAdvancedColorInfo可能报告 NaN 或越界的色彩 primaries。保存截图时这些畸形值喂给ICCHelper/lcms2,破坏 GC 堆,导致进程崩溃(0xC0000005)。修复
GetColorPrimariesFromDisplayInformationAsync内校验 primaries —— 任一 primary 非有限、超出 (0,1) 范围、或违反 x+y≤1 CIE 物理约束,则 fallback BT709,避免崩溃(不写畸形 ICC chunk)。范围
单文件改动,纯逻辑兜底。不改默认值、UI、字符串 —— 正常显示器行为不变。