Skip to content

fix(core): make the Linux icon lookup find icons, and read them defensively - #2289

Open
aibizagility wants to merge 1 commit into
safing:developmentfrom
aibizagility:fix/linux-icon-lookup
Open

aibizagility wants to merge 1 commit into
safing:developmentfrom
aibizagility:fix/linux-icon-lookup

Conversation

@aibizagility

@aibizagility aibizagility commented Oct 12, 2026 •

Copy link
Copy Markdown

Summary

On Linux, core produced no icons: the lookup compared absolute binary paths with icon file stems, so nothing matched, and a separate extension bug would have prevented importing a match. Two defects in service/profile/binmeta:

  • find_linux.go compared the full binary path (/usr/bin/firefox) against icon file stems (firefox), so nothing matched.
  • LoadAndSaveIcon passed filepath.Ext(path) (.png) to UpdateProfileIcon, which expects png and rejected it. The default icon of Windows service profiles (svchost_windows.go) goes through the same call and fails the same way.

Change

  • Match the binary's lower-cased base name against supported icon file stems, return full paths for prefix matches, and include hicolor/scalable. Exact name match in any location wins over a prefix match in any location; among prefix matches the shortest wins, earlier locations first on ties. Directories named like a match are skipped. The first directory error is reported only when nothing was found.
  • Core runs as root, so the lookup is conservative on purpose:
    • only system locations assumed administrator-controlled are searched: /usr/share/pixmaps, /usr/share, /usr/local/share, /var/lib/flatpak/exports/share, /usr/share/<name>. The per-user locations (~/.local/share, ~/.local/share/flatpak) are no longer searched by core; the UI resolves those as the user.
    • all LoadAndSaveIcon callers now require a regular file, at most 1 MB, and a matching format signature; SVG is checked through its first XML element, which must be <svg> (strict decoder). Reads take one extra byte to detect growth; non-Windows opens are non-blocking so a FIFO cannot stall core. Symlinks are followed (flatpak exports are symlink farms); ownership is not checked.

Effect

Linux profile creation can import a Source: core icon when a filename match passes validation; prefix matching remains a heuristic, so a binary without its own icon can still match another file by prefix. The extension fix also lets Windows service profiles import their default icon again.

Tests

Verify with go test -race ./service/profile/.... New tests cover searchDirectory (exact, prefix, dotted names, case, directory skip, missing vs broken directory), searchForIcon preference order and first-error retention, readIconFile (signatures of all formats, SVG root, symlink to image and to non-image, size boundary, FIFO, directory) and the LoadAndSaveIcon extension round trip. Unit tests pass on Linux (Go 1.26). Verified on Linux Mint 22 with F3a, F4 and F5 applied to 2.2.3: newly created profiles for /usr/lib/chatgpt/ChatGPT and /usr/lib/claude-desktop/claude-desktop received Source: core icons; inspected profiles for binaries without matching system icons received no core icon.

🤖 Generated with Claude Code & Codex under SCI collaboration

Summary by CodeRabbit

  • Bug Fixes
    • Improved Linux application icon matching, with exact matches prioritized over similar names and consistent tie-breaking across system locations.
    • Icon files are now checked for supported formats, valid content, and reasonable size before use, helping prevent invalid or unsuitable files from being loaded.
    • Expanded system-wide icon lookup to include additional shared locations. Missing directories no longer prevent icons from being found elsewhere.

@CLAassistant

CLAassistant commented Oct 12, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@coderabbitai

coderabbitai Bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 27fe58d8-f7c3-4314-83f7-821fcb12c86c

📥 Commits

Reviewing files that changed from the base of the PR and between eacf3a3 and 2aa5ad7.


📒 Files selected for processing (3)
  • service/profile/binmeta/find_linux.go
  • service/profile/binmeta/find_linux_test.go
  • service/profile/binmeta/locations_linux.go

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 6 remain after this review.



📝 Walkthrough

Walkthrough

Linux icon lookup searches configured system locations by binary basename, with exact matches preferred over prefix matches. Icon loading validates file type, size, and content before importing. Tests cover lookup precedence, file validation, and loading.

Changes

Linux icon lookup

Layer / File(s) Summary
System locations and icon matching
service/profile/binmeta/locations_linux.go, service/profile/binmeta/find_linux.go, service/profile/binmeta/find_linux_test.go
Lookup uses configured system icon locations and the binary basename. It searches for exact matches before prefixes, ranks prefixes by extra filename length, and retains earlier locations on ties. Tests cover matching, precedence, and lookup errors.
Icon file validation and import
service/profile/binmeta/icons.go, service/profile/binmeta/icons_open_*.go, service/profile/binmeta/find_linux_test.go
Icon loading rejects non-regular or oversized files and content that does not match the file extension. Unix opens files without blocking; Windows uses os.Open. Tests cover format validation, special files, and loading.

Priority: ➖ Normal

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix


Merge Risk: ⚪ Minimal · up to 2aa5a

No confirmed issue remains that needs resolution before merging.

Pre-merge checks | Passed 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly summarizes the two primary changes: fixing Linux icon lookup and making icon reads defensive.
Docstring Coverage Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 17 functions across 6 files.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@aibizagility
aibizagility force-pushed the fix/linux-icon-lookup branch from 13e620a to eacf3a3 Compare October 12, 2026 04:18
…sively

On Linux, core found no icon for any binary (GetIconAndName always
returned nil), so every profile icon came from the UI's process-based
resolver. Two defects in binmeta:

- find_linux.go compared the full binary path (e.g. "/usr/bin/firefox")
  against icon file stems ("firefox"), so nothing ever matched.
- LoadAndSaveIcon passed filepath.Ext(path) (".png") to UpdateProfileIcon,
  which expects the extension without the dot ("png") and rejected it.

The lookup now compares the lower-cased base name of the binary against
file stems. An exact name match in any location wins over a prefix match
in any location; among prefix matches the shortest wins, earlier locations
first on ties. Directories named like a match are skipped, and the first
directory error is kept and reported only when nothing was found.

Core runs as root, so the locations and the read are deliberately
conservative:

- Only root-owned trees are searched: /usr/share/pixmaps, /usr/share,
  /usr/local/share, /var/lib/flatpak/exports/share and /usr/share/<name>.
  The per-user locations (~/.local/share, ~/.local/share/flatpak) are no
  longer searched by core; the UI resolves those as the user.
- readIconFile opens without blocking (a FIFO cannot stall core), only
  accepts a regular file on the open handle, reads at most 1 MB, and
  requires the bytes to carry the signature of the format the extension
  announces; for SVG the first XML element must be <svg>. The locations
  are assumed administrator-controlled; ownership is not checked.

Effect: freshly created profiles on Linux now get a core-sourced icon
when the binary has one in the standard locations, instead of waiting
for the UI to guess from a running process. The only other caller of
LoadAndSaveIcon is the default icon of Windows service profiles
(service/process/tags/svchost_windows.go), which was failing the same
way and is repaired by the ".png" fix as well.

Tests: searchDirectory (exact, prefix, dotted names, case, directory
skip, missing vs broken directory), searchForIcon preference order and
first-error retention, readIconFile (signatures of all formats, SVG root
element, symlink to image and to non-image, size boundary, FIFO,
directory) and the LoadAndSaveIcon extension round trip.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@aibizagility
aibizagility force-pushed the fix/linux-icon-lookup branch from eacf3a3 to 2aa5ad7 Compare October 12, 2026 04:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants