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

gh-100256: Skip inaccessible registry keys in the WinAPI mimetype implementation #122047

Conversation

LucasEsposito
Copy link
Contributor

@LucasEsposito LucasEsposito commented Jul 19, 2024

Currently there are two implementations to load mimetypes in Windows from registry keys:

  • WinReg: Former and slower implementation written in Python. Currently used as fallback. If it can't access a registry key, that key is just skipped and continues with the next.
  • WinAPI: Faster implementation in C. It's prioritized over WinReg one. If it can't access a registry key, it fails.

The current behavior of WinAPI results in some problems, as you can read in the issue description and comments.

This PR addresses those discrepancies in the behavior across different implenentations, making the new WinAPI behave on the same way as the fallback WinReg solution.

@LucasEsposito LucasEsposito requested a review from a team as a code owner July 19, 2024 19:12
Copy link

cpython-cla-bot bot commented Jul 19, 2024

All commit authors signed the Contributor License Agreement.
CLA signed

@LucasEsposito LucasEsposito changed the title [3.13pythongh-100256: Read Windows registry with the fallback implementati… [3.13] gh-100256: Read Windows registry with the fallback implementation if the accelerated one fails Jul 19, 2024
@LucasEsposito LucasEsposito force-pushed the gh-100256-denied_access_to_windows_mimetype_registry_keys branch from 0ffc526 to 7b2e83b Compare July 19, 2024 19:53
@LucasEsposito LucasEsposito changed the title [3.13] gh-100256: Read Windows registry with the fallback implementation if the accelerated one fails [3.13] gh-100256: Skip inaccessible registry keys in the WinAPI implementation Jul 19, 2024
@LucasEsposito LucasEsposito changed the title [3.13] gh-100256: Skip inaccessible registry keys in the WinAPI implementation [3.13] gh-100256: Skip inaccessible registry keys in the WinAPI mimetype implementation Jul 19, 2024
@LucasEsposito LucasEsposito force-pushed the gh-100256-denied_access_to_windows_mimetype_registry_keys branch from 7b2e83b to 6922a1d Compare July 19, 2024 20:07
@LucasEsposito LucasEsposito changed the title [3.13] gh-100256: Skip inaccessible registry keys in the WinAPI mimetype implementation gh-100256: Skip inaccessible registry keys in the WinAPI mimetype implementation Jul 19, 2024
Modules/_winapi.c Outdated Show resolved Hide resolved
@LucasEsposito LucasEsposito force-pushed the gh-100256-denied_access_to_windows_mimetype_registry_keys branch from 78a4bad to b19eac6 Compare July 21, 2024 23:27
LucasEsposito and others added 2 commits July 22, 2024 01:57
Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
@LucasEsposito LucasEsposito force-pushed the gh-100256-denied_access_to_windows_mimetype_registry_keys branch from b19eac6 to ad3c57c Compare July 21, 2024 23:57
Copy link
Contributor

@ZeroIntensity ZeroIntensity left a comment

Choose a reason for hiding this comment

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

Nice PR, LGTM

@@ -2806,6 +2806,11 @@ _winapi__mimetypes_read_windows_registry_impl(PyObject *module,
if (err == ERROR_FILE_NOT_FOUND) {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if (err == ERROR_FILE_NOT_FOUND) {
if (err == ERROR_FILE_NOT_FOUND || err == ERROR_ACCESS_DENIED) {

May as well just do this instead of adding the extra case (we can't PyErr_Set... here anyway because the GIL is released).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the improvement. It's fixed now

Misc/ACKS Outdated
@@ -2104,5 +2104,6 @@ Jelle Zijlstra
Gennadiy Zlobin
Doug Zongker
Peter Åstrand
Lucas Esposito
Copy link
Member

Choose a reason for hiding this comment

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

Find the E names to add yourself to (line immediately below here says to use alphabetical order, which for English alphabets doesn't have to be "rough").

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed! My bad.

In a quick look I though the list had no apparent order... but it was just that the list started with first name even though it's sorted by last name. I didn't notice at first

@zooba zooba added needs backport to 3.12 bug and security fixes needs backport to 3.13 bugs and security fixes labels Aug 7, 2024
Modules/_winapi.c Outdated Show resolved Hide resolved
@zooba
Copy link
Member

zooba commented Aug 7, 2024

If CI passes with that little fix I committed myself, we should be good to merge.

@zooba zooba merged commit 0bd9375 into python:main Aug 7, 2024
37 checks passed
@miss-islington-app
Copy link

Thanks @LucasEsposito for the PR, and @zooba for merging it 🌮🎉.. I'm working now to backport this PR to: 3.12, 3.13.
🐍🍒⛏🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Aug 7, 2024
…pe implementation (pythonGH-122047)

(cherry picked from commit 0bd9375)

Co-authored-by: Lucas Esposito <LucasEsposito@users.noreply.github.com>
@bedevere-app
Copy link

bedevere-app bot commented Aug 7, 2024

GH-122786 is a backport of this pull request to the 3.13 branch.

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Aug 7, 2024
…pe implementation (pythonGH-122047)

(cherry picked from commit 0bd9375)

Co-authored-by: Lucas Esposito <LucasEsposito@users.noreply.github.com>
@bedevere-app bedevere-app bot removed the needs backport to 3.13 bugs and security fixes label Aug 7, 2024
@bedevere-app
Copy link

bedevere-app bot commented Aug 7, 2024

GH-122787 is a backport of this pull request to the 3.12 branch.

@bedevere-app bedevere-app bot removed the needs backport to 3.12 bug and security fixes label Aug 7, 2024
zooba pushed a commit that referenced this pull request Aug 7, 2024
…lementation (GH-122047)

(cherry picked from commit 0bd9375)

Co-authored-by: Lucas Esposito <LucasEsposito@users.noreply.github.com>
blhsing pushed a commit to blhsing/cpython that referenced this pull request Aug 22, 2024
Yhg1s pushed a commit that referenced this pull request Sep 2, 2024
…ype implementation (GH-122047) (#122786)

gh-100256: Skip inaccessible registry keys in the WinAPI mimetype implementation (GH-122047)
(cherry picked from commit 0bd9375)

Co-authored-by: Lucas Esposito <LucasEsposito@users.noreply.github.com>
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.

3 participants