Skip to content

PyArg_ParseTuple(args, "u#", ...) misbehaves with -Werror #94864

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

Closed
jwilk opened this issue Jul 14, 2022 · 0 comments
Closed

PyArg_ParseTuple(args, "u#", ...) misbehaves with -Werror #94864

jwilk opened this issue Jul 14, 2022 · 0 comments
Assignees
Labels
3.10 only security fixes 3.11 only security fixes

Comments

@jwilk
Copy link

jwilk commented Jul 14, 2022

PyArg_ParseTuple(args, "u#", ...) generates a deprecation warning, as expected:

$ python3 --version
Python 3.11.0b4
$ python3 -c 'import _testcapi as t; t.getargs_u_hash("")'
<string>:1: DeprecationWarning: getargs: The 'u' format is deprecated. Use 'U' instead.

But when I turn warnings into exceptions, something weird happens:

$ python3 -Werror -c 'import _testcapi as t; t.getargs_u_hash("")'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
ValueError: character U+b4000360 is not in range [U+0000; U+10ffff]

What's going on here? The code for getargs_u_hash() looks like this:

Py_UNICODE *str;
Py_ssize_t size;
if (!PyArg_ParseTuple(args, "u#", &str, &size))
    return NULL;
return PyUnicode_FromWideChar(str, size);

So it looks like PyArg_ParseTuple() returns true, but leaves str and size uninitialized.

@serhiy-storchaka serhiy-storchaka self-assigned this Jul 16, 2022
@serhiy-storchaka serhiy-storchaka added the 3.11 only security fixes label Jul 16, 2022
serhiy-storchaka added a commit to serhiy-storchaka/cpython that referenced this issue Jul 16, 2022
… "Z"

It returned 1 (success) when warnings are turned into exceptions.
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Jul 17, 2022
… "Z" (pythonGH-94902)

It returned 1 (success) when warnings are turned into exceptions.
(cherry picked from commit 107c21c)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
serhiy-storchaka added a commit that referenced this issue Jul 17, 2022
…H-94902)

It returned 1 (success) when warnings are turned into exceptions.
miss-islington added a commit that referenced this issue Jul 17, 2022
…H-94902)

It returned 1 (success) when warnings are turned into exceptions.
(cherry picked from commit 107c21c)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
@serhiy-storchaka serhiy-storchaka added the 3.10 only security fixes label Jul 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.10 only security fixes 3.11 only security fixes
Projects
None yet
Development

No branches or pull requests

2 participants