Skip to content

fix: Electron creates temporary icon files and does not delete them after use - #52424

Merged
ckerr merged 5 commits into
electron:mainfrom
huangfanglong:remove-tmp-icos
Jul 27, 2026
Merged

ckerr merged 5 commits into
electron:mainfrom
huangfanglong:remove-tmp-icos

Conversation

@huangfanglong

Copy link
Copy Markdown
Contributor

Description of Change

Fixes #52354

Previously, every ASAR ICO used Archive::CopyFileOut(). For packed files, that function stores the extracted file in Archive::external_files_. Since Electron caches ASAR archives globally, those temporary files remain alive and are never removed normally.

On Windows, Electron temporarily extract an ICO stored inside an ASAR archive before passing it to LoadImage. The previous implementation cached that extracted file for the lifetime of the process, which left *.tmp.ico files behind.

This change writes packed ICO data to a scoped temporary directory instead. The directory is removed immediately after Windows creates the in-memory HICON. ICO files marked as unpacked continue to load directly from app.asar.unpacked.

Checklist

Release Notes

Notes: Fixed an issue where loading ICO files from ASAR archives on Windows left temporary icon files behind.

@welcome

welcome Bot commented Jul 22, 2026

Copy link
Copy Markdown

💖 Thanks for opening this pull request! 💖

Semantic PR titles

We use semantic commit messages to streamline the release process. Before your pull request can be merged, you should update your pull request title to start with a semantic prefix.

Examples of commit messages with semantic prefixes:

  • fix: don't overwrite prevent_default if default wasn't prevented
  • feat: add app.isPackaged() method
  • docs: app.isDefaultProtocolClient is now available on Linux

Commit signing

This repo enforces commit signatures for all incoming PRs.
To sign your commits, see GitHub's documentation on Telling Git about your signing key.

PR tips

Things that will help get your PR across the finish line:

  • Follow the JavaScript, C++, and Python coding style.
  • Run npm run lint locally to catch formatting errors earlier.
  • Document any user-facing changes you've made following the documentation styleguide.
  • Include tests when adding/changing behavior.
  • Include screenshots and animated GIFs whenever possible.

We get a lot of pull requests on this repo, so please be patient and we will get back to you as soon as we can.

@electron-cation electron-cation Bot added the new-pr 🌱 PR opened recently label Jul 22, 2026
@github-actions

Copy link
Copy Markdown
Contributor

⚠️ This PR contains unsigned commits. This repository enforces commit signatures
for all incoming PRs. To get your PR merged, please sign those commits
(git rebase --exec 'git commit -S --amend --no-edit -n' @{upstream}) and force push them to this branch
(git push --force-with-lease)

For more information on signing commits, see GitHub's documentation on Telling Git about your signing key.

@github-actions github-actions Bot added the needs-signed-commits Currently some or all of the commits in this PR are not signed label Jul 22, 2026
- Valid packed ICO cleanup
- Unpacked ASAR ICO behavior
- Missing ICO entry
- Missing ASAR archive
- Invalid packed ICO cleanup
- Repeated loading of the same ICO
- Loading multiple distinct ICOs
- Loading through an ASAR link
- Exclude icon.asar from the generic repacker so its packed, unpacked, and linked entries keep their intended structure
- Assisted-By: GPT 5.6 Sol, OpenCode
@github-actions github-actions Bot removed the needs-signed-commits Currently some or all of the commits in this PR are not signed label Jul 22, 2026
@ckerr
ckerr self-requested a review July 23, 2026 15:25
@ckerr ckerr added the semver/patch backwards-compatible bug fixes label Jul 23, 2026

@ckerr ckerr left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code LGTM.

TBH I'd also be open to doing this all in-memory to avoid the filesystem round-trip and disk IO edge cases (eg disk full), but that's out-of-scope for a bugfix. If anyone wants to take that on as a refactor for 45-x-y I'd be happy to review.

@ckerr ckerr added target/42-x-y PR should also be added to the "42-x-y" branch. target/43-x-y PR should also be added to the "43-x-y" branch. target/44-x-y PR should also be added to the "44-x-y" branch. labels Jul 23, 2026
@electron-cation electron-cation Bot removed the new-pr 🌱 PR opened recently label Jul 23, 2026
@olfek

olfek commented Jul 26, 2026

Copy link
Copy Markdown

Better, but pointless disk wear and tear is still present.

@olfek

olfek commented Jul 26, 2026

Copy link
Copy Markdown

I come from --- docker/for-win#13826 --- btw

@dsanders11 dsanders11 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is anything preventing using asar::ScopedTemporaryFile::InitFromFile in the implementation, instead of base::ScopedTempDir? Seems like it would be cleaner and stay closer to the current implementation.

@ckerr

ckerr commented Jul 27, 2026

Copy link
Copy Markdown
Member

Is anything preventing using asar::ScopedTemporaryFile::InitFromFile in the implementation, instead of base::ScopedTempDir? Seems like it would be cleaner and stay closer to the current implementation.

This won't work on Windows: ScopedTemporaryFile::~ScopedTemporaryFile() uses base::DeleteFileAfterReboot(path_); so the file isn't removed until the OS reboots. This won't pass CI's cleanups tests and probably wouldn't be great for long-running production code eg kiosks.

I do think the long-term solution is to bypass the temporary directory altogether and do this in-memory though.

@dsanders11

Copy link
Copy Markdown
Member

I do think the long-term solution is to bypass the temporary directory altogether and do this in-memory though.

Agreed. I looked into it briefly, and unfortunately an in-memory implementation has some edge cases we'd need to ensure we're properly covering, so for now I'm good with this improvement.

@ckerr
ckerr merged commit d84976d into electron:main Jul 27, 2026
81 checks passed
@welcome

welcome Bot commented Jul 27, 2026

Copy link
Copy Markdown

Congrats on merging your first pull request! 🎉🎉🎉

@release-clerk

release-clerk Bot commented Jul 27, 2026

Copy link
Copy Markdown

Release Notes Persisted

Fixed an issue where loading ICO files from ASAR archives on Windows left temporary icon files behind.

@trop

trop Bot commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

I have automatically backported this PR to "44-x-y", please check out #52477

@trop

trop Bot commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

I have automatically backported this PR to "43-x-y", please check out #52478

@trop

trop Bot commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

I have automatically backported this PR to "42-x-y", please check out #52479

@trop trop Bot added in-flight/43-x-y in-flight/42-x-y merged/43-x-y PR was merged to the "43-x-y" branch. merged/44-x-y PR was merged to the "44-x-y" branch. and removed target/43-x-y PR should also be added to the "43-x-y" branch. target/42-x-y PR should also be added to the "42-x-y" branch. in-flight/43-x-y in-flight/44-x-y labels Jul 27, 2026
@huangfanglong
huangfanglong deleted the remove-tmp-icos branch July 28, 2026 06:09
@trop trop Bot added merged/42-x-y PR was merged to the "42-x-y" branch. and removed in-flight/42-x-y labels Jul 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

45-x-y merged/42-x-y PR was merged to the "42-x-y" branch. merged/43-x-y PR was merged to the "43-x-y" branch. merged/44-x-y PR was merged to the "44-x-y" branch. semver/patch backwards-compatible bug fixes

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

Electron creates temporary icon files and does not delete them after use

4 participants