Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Windows registry access mode when adding icons to file type associations #206

Merged
merged 6 commits into from
May 10, 2024

Conversation

marcoesters
Copy link
Contributor

Description

When adding an icon to a file type association in the Windows registry, the subkey is opened with read-only access. This leads to a permission error when trying to add the icon. This was not caught by tests because the data file did not have the icon key set.

Opening the subkey with KEY_SET_VALUE correctly adds the icon file.

Closes #191.

Checklist - did you ...

  • Add a file to the news directory (using the template) for the next release's release notes?
  • Add / update necessary tests?
  • Add / update outdated documentation?

@conda-bot conda-bot added the cla-signed [bot] added once the contributor has signed the CLA label May 7, 2024
@marcoesters marcoesters marked this pull request as ready for review May 7, 2024 20:52
@marcoesters marcoesters requested a review from a team as a code owner May 7, 2024 20:52
@@ -72,7 +72,7 @@ def register_file_extension(extension, identifier, command, icon=None, mode="use
log.debug("Created registry entry for command '%s'", command)

if icon:
subkey = winreg.OpenKey(key, identifier)
subkey = winreg.OpenKey(key, identifier, access=winreg.KEY_SET_VALUE)
Copy link
Contributor

Choose a reason for hiding this comment

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

Awesome catch!

We don't need this anywhere else for other keys, right? Thinking of file type association and so on.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The only other key we open is here:

with winreg.OpenKeyEx(
(
winreg.HKEY_LOCAL_MACHINE if mode == "system" else winreg.HKEY_CURRENT_USER # HKLM
), # HKCU
r"Software\Classes",
) as key:

This is done with write-only access as the default. However, we only write to subkeys and the documentation there is a little confusing:

The key identified by the key parameter must have been opened with KEY_SET_VALUE access.

However, when a subkey is not null, the source code suggests that they are always opened with KEY_SET_VALUE access: https://github.com/python/cpython/blob/6d419db10c84cacbb3862e2adc940342175bfce9/PC/winreg.c#L1787-L1796

My interpretation is that the reason the icon fails is that we don't explicitly pass a subkey value, but instead operate on the key object itself.

Copy link
Contributor

Choose a reason for hiding this comment

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

Got it. So for now no action needed but let's keep an eye for reports in case we need to pass more access flags. Thanks for the research!

jaimergp
jaimergp previously approved these changes May 8, 2024
Co-authored-by: jaimergp <jaimergp@users.noreply.github.com>
@jaimergp jaimergp merged commit 2416e74 into conda:main May 10, 2024
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla-signed [bot] added once the contributor has signed the CLA
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Windows PermissionError: [WinError 5] Zugriff verweige done
3 participants