Skip to content

Windows tray icons incorrectly load multi-image ICO files #5961

Closed

Description

@nik9play

Description

On Windows, SystemTray.SetIcon and application/window icon loading handle PNG bytes correctly but pass a complete multi-image ICO container directly to CreateIconFromResourceEx. That API expects the bytes of one RT_ICON image resource, not the ICO file header, directory, and all image entries. As a result, .ico files can fail to load or render/select incorrectly in the system tray.

Reproduction

  1. Embed a conventional multi-size ICO containing 16, 32, 48, and/or 256 pixel images.
  2. Pass its bytes to app.SystemTray.New().SetIcon(icon) on Windows.
  3. Run the application and inspect the tray icon.
//go:embed icon.ico
var icon []byte

tray := app.SystemTray.New()
tray.SetIcon(icon)

Root cause

v3/pkg/w32/icon.go recognizes the ICO signature, but CreateSmallHIconFromImage and CreateLargeHIconFromImage pass the entire file buffer to CreateIconFromResourceEx. ICO files need to be parsed and the best matching ICONDIRENTRY payload extracted first.

Scope

  • Parse the ICO header and directory safely.
  • Select the best image for the requested Windows system metric, preferring the closest size that does not exceed it and then color depth.
  • Pass only the selected PNG/DIB image payload to CreateIconFromResourceEx.
  • Preserve direct PNG support.
  • Cover multi-image selection, 256-pixel entries, malformed bounds, and actual HICON creation with tests.

Acceptance criteria

  • Multi-image ICO bytes produce a non-null Windows HICON.
  • The closest suitable image entry is selected deterministically.
  • Malformed ICO offsets and lengths return an error without panicking.
  • Existing PNG icon loading continues to work.

Activity

  1. coderabbitai commented on Aug 12, 2026

    @coderabbitai
    Contributor
    🔗 Related PRs

    #4653 - [v3 alpha] windows tray minor refactor [merged]
    #4706 - Fix Windows systray icon regression [merged]
    #5576 - fix(v3/windows): show dialogs with icons in dev builds and keep their buttons [merged]
    #5627 - test(v3/icons): assert .ico is small, not an exact byte size [merged]
    #5703 - fix(v3/windows): systray panic [merged]


    📝 Issue Planner

    Check the box below or use the @coderabbitai plan command to generate an implementation plan and prompts that you can use with your favorite coding assistant.

    • Create Plan

    🧪 Issue enrichment is currently in open beta.

    You can configure auto-planning by selecting labels in the issue_enrichment configuration.

    To disable automatic issue enrichment, add the following to your .coderabbit.yaml:

    issue_enrichment:
      auto_enrich:
        enabled: false

    💬 Have feedback or questions? Drop into our discord!

  2. nik9play commented on Aug 12, 2026

    @nik9play
    ContributorAuthor

    Closing because this issue was opened prematurely during local investigation. The fix remains local and unsubmitted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions