Skip to content

Unsafe cast from Py_ssize_t to int #9

@msancheznet

Description

@msancheznet

Before Python 3.10, the Python C interface used the int type for arguments of variable data size such as s#, y#, u# and U# (see https://docs.python.org/3/c-api/arg.html), unless the macro PY_SSIZE_T_CLEAN was defined prior to any calls to #include python.h, in which cast Py_ssize_t was used instead. However, as of Python 3.10, only Py_ssize_t can be used.

Version of pyion prior to 4.1.2 used int and did not define PY_SSIZE_T_CLEAN. pyion 4.1.2 has upgraded the interface to Py_ssize_t, which is a 64-bit integer in 64-bit platforms. This means, for example, that a bundle of size 264-1 can be delivered to via pyion, even though ION only accepts payloads up to 232-1.To solve this issue, pyion currently performs an unsafe cast from Py_ssize_t to int, with the assumption that no one will attempt to transmit a bundle of size greater than 2**32-1 anyways. A better approach would be to protect against payloads that are too large, thus avoid potential integer overflows during the casting operation.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions