win32: Copy icon pixels to BGRA instead of mutating the shared buffer - #4677
Merged
kchibisov merged 2 commits intoSep 3, 2026
Merged
Conversation
kchibisov
reviewed
Sep 2, 2026
kchibisov
reviewed
Sep 3, 2026
`from_rgba` takes an immutable borrow and no longer uses the unsafe in-place reinterpretation, so it can't touch the shared buffer by construction; the regression test was asserting a compiler-guaranteed invariant.
kchibisov
approved these changes
Sep 3, 2026
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.
Note
This PR is AI-implemented — it was written by an AI coding agent at the request of @sena-nana. If the approach doesn't fit the project's direction, the problem should be solved differently, or any other consideration applies, please feel free to close it without any concern.
What the bug causes
WinIcon::from_rgbaconverts the caller's RGBA buffer to BGRA in place, through a raw pointer derived from a shared reference (&RgbaIcon).Two consequences:
Iconconverts differently on every call.Iconwraps anArc<dyn IconProvider>, soIcon::clone()shares the pixel buffer. Any code path that applies one icon more than once — e.g. building both the window icon and the taskbar icon from the same clone, or re-applying an icon at runtime — makes the secondfrom_rgbacall read the already-BGRA buffer and flip it back. The second HICON then displays with red and blue swapped. We hit this in practice: a blue app icon (73, 145, 215) rendered orange (215, 145, 73) in the Windows taskbar and Alt-Tab, while the title-bar icon (the first conversion) stayed correct.&RgbaIcon, which may be shared viaArc, which is undefined behavior.The fix
Copy RGBA → BGRA into an owned buffer instead of mutating the input. This makes
from_rgbaidempotent, keeps the first-consumer output byte-identical to before, and removes the unsafe pointer cast entirely. The now-deadPixelstruct is removed.Verification
cargo check -p winit-win32 --target x86_64-pc-windows-msvc --all-targetsandcargo clippy -p winit-win32 --target x86_64-pc-windows-msvc --all-targets -- -D warningspass locally.x86_64-pc-windows-msvc, Windows coverage kindly requested from CI)changelogmodule if knowledge of this change could be valuable to users