-
-
Notifications
You must be signed in to change notification settings - Fork 31.9k
gh-106844: Fix null-bytes handling in LCMapStringEx
in _winapi
#106857
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
Conversation
Modules/_winapi.c
Outdated
@@ -1537,42 +1537,66 @@ _winapi_PeekNamedPipe_impl(PyObject *module, HANDLE handle, int size) | |||
/*[clinic input] | |||
_winapi.LCMapStringEx | |||
|
|||
locale: LPCWSTR | |||
locale: unicode |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why change it for locale
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just backported the solution from 927b5af#diff-42415407f8d0ef2d42e29d13d979f633e3543770e62c3871e1101ad532d336a8R1518
So, 3.11 and 3.12 would match.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code would be simpler if keep the LPCWSTR converter here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree. We don't need to treat this argument any differently - it's only the src
argument that requires special handling.
Modules/_winapi.c
Outdated
srcLen = (int)srcLenAsSsize; | ||
if (srcLen != srcLenAsSsize) { | ||
srcLen = -1; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How would it work for large (more than 2**32
characters) string containing NUL?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It doesn't, but that's the caller's responsibility.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LCMapStringEx()
will simply return the result for the truncated input. It is bad. How is the caller expected to detect this problem if it only occurs in special circumferences?
What does LCMapStringEx()
return for large input not containing NUL? Most likely it fails. We should either emulate this response (raise an OSError with the same Windows error code) or simply raise an OverflowError.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please address my comments. If the code in 3.11 has the same flaws, it should be fixed too.
Modules/_winapi.c
Outdated
@@ -1537,42 +1537,66 @@ _winapi_PeekNamedPipe_impl(PyObject *module, HANDLE handle, int size) | |||
/*[clinic input] | |||
_winapi.LCMapStringEx | |||
|
|||
locale: LPCWSTR | |||
locale: unicode |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code would be simpler if keep the LPCWSTR converter here.
A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated. Once you have made the requested changes, please leave a comment on this pull request containing the phrase |
I don't think the fix is as simple as bringing forward this fix - the underlying code should be identical in current versions, it was just earlier versions that needed a different fix because of existing bugs in the Unicode converters. I'll take a fresh look and see what ought to happen here. Chances are, updating the |
Looks like the changes to make argument clinic support Leaving the |
Opened #107832 for my propositions. |
#107832 fixed also other issues. |
I've changed the clinic definition + backported changes made by @zooba in 927b5af#diff-42415407f8d0ef2d42e29d13d979f633e3543770e62c3871e1101ad532d336a8