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

object.__basicsize__ is erroneously 0 on big-endian 64-bit machines (int vs Py_ssize_t) #53897

Closed
davidmalcolm opened this issue Aug 25, 2010 · 2 comments
Labels
type-bug An unexpected behavior, bug, or error

Comments

@davidmalcolm
Copy link
Member

BPO 9688
Nosy @benjaminp, @davidmalcolm
Files
  • fix-typeobject-T_INT-usage.patch: Patch against 2.7 branch
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2010-08-25.23:13:27.378>
    created_at = <Date 2010-08-25.22:44:35.116>
    labels = ['type-bug']
    title = 'object.__basicsize__ is erroneously 0 on big-endian 64-bit machines (int vs Py_ssize_t)'
    updated_at = <Date 2010-08-25.23:13:27.376>
    user = 'https://github.com/davidmalcolm'

    bugs.python.org fields:

    activity = <Date 2010-08-25.23:13:27.376>
    actor = 'benjamin.peterson'
    assignee = 'none'
    closed = True
    closed_date = <Date 2010-08-25.23:13:27.378>
    closer = 'benjamin.peterson'
    components = []
    creation = <Date 2010-08-25.22:44:35.116>
    creator = 'dmalcolm'
    dependencies = []
    files = ['18646']
    hgrepos = []
    issue_num = 9688
    keywords = ['patch']
    message_count = 2.0
    messages = ['114942', '114947']
    nosy_count = 2.0
    nosy_names = ['benjamin.peterson', 'dmalcolm']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'patch review'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue9688'
    versions = ['Python 2.7']

    @davidmalcolm
    Copy link
    Member Author

    On 64-bit bigendian machines (ppc64 and s390x), I'm seeing:
    >>> print object.__basicsize__
    0

    (Discovered via a segfault in Jinja2 tries to use ctypes to manipulate ob_refcnt of variables, and gets the wrong location, corrupting the objects instead; see https://bugzilla.redhat.com/show_bug.cgi?id=627347 )

    struct _typeobject declares tp_basicsize and tp_itemsize as Py_ssize_t:
    {
    ...
    Py_ssize_t tp_basicsize, tp_itemsize; /* For allocation */
    ...
    }

    but type_members defines them as T_INT:
    {"__basicsize__", T_INT, offsetof(PyTypeObject,tp_basicsize),READONLY},
    {"__itemsize__", T_INT, offsetof(PyTypeObject, tp_itemsize), READONLY},

    Hence when accessing "object.__basicsize__", PyMember_GetOne reads it as a
    T_INT, which gets it as 0 (incorrect). Accessing it as Py_ssize_t reads it as
    16 (correct)
    (gdb) p *(Py_ssize_t*)addr
    $9 = 16
    (gdb) p *(int*)addr
    $10 = 0

    I'm attaching a patch which changes them to use T_PYSSIZE_T and adds a selftest.

    @davidmalcolm davidmalcolm changed the title object.__basicsize__ is erroneously0 object.__basicsize__ is erroneously 0 on big-endian 64-bit machines (int vs Py_ssize_t) Aug 25, 2010
    @davidmalcolm davidmalcolm added the type-bug An unexpected behavior, bug, or error label Aug 25, 2010
    @benjaminp
    Copy link
    Contributor

    r84320.

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants