Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • pypy pypy
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 675
    • Issues 675
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 13
    • Merge requests 13
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Container Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • PyPyPyPy
  • pypypypy
  • Issues
  • #3661
Closed
Open
Issue created Feb 02, 2022 by Michał Górny@mgornyDeveloper

pypy3.9: wrong prototype + segv in PyUnicode_DecodeLocale()

This affects pycurl.

/usr/include/pypy3.9/pypy_decl.h declares:

PyAPI_FUNC(struct _object *) PyUnicode_DecodeLocale(struct _object *arg0, const char *arg1);

However, according to https://docs.python.org/3/c-api/unicode.html#c.PyUnicode_DecodeLocale, it should be:

PyObject *PyUnicode_DecodeLocale(const char *str, const char *errors)

i.e. take const char * as 1st arg.

Given a fixed string, it segfaults.

My cheap reproducer:

foomodule.c:

#define PY_SSIZE_T_CLEAN
#include <Python.h>

static PyObject *
frobnicate(PyObject *self, PyObject *args)
{
    return PyUnicode_DecodeLocale("Couldn't bind to 'not-interface-or-ip'\0r-ip",
                                  "surrogateescape");
}

static PyMethodDef FooMethods[] = {
    {"frobnicate",  frobnicate, METH_VARARGS,
     "frobnicate."},
    {NULL, NULL, 0, NULL}        /* Sentinel */
};

static struct PyModuleDef foomodule = {
    PyModuleDef_HEAD_INIT,
    "foo",   /* name of module */
    NULL, /* module documentation, may be NULL */
    -1,       /* size of per-interpreter state of the module,
                 or -1 if the module keeps state in global variables. */
    FooMethods
};

PyMODINIT_FUNC
PyInit_foo(void)
{
    return PyModule_Create(&foomodule);
}

setup.py:

from setuptools import setup, Extension

setup(name='foo',
      ext_modules=[
          Extension('foo', sources=['foomodule.c']),
      ])

Using CPython:

>>> import foo
>>> foo.frobnicate()
"Couldn't bind to 'not-interface-or-ip'"

Using PyPy3.9:

>>>> import foo
>>>> foo.frobnicate()
Segmentation fault (core dumped)
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Assignee
Assign to
Time tracking