[Python-Dev] r43041 - python/trunk/Modules/_ctypes/cfield.c

Jim Jewett jimjjewett at gmail.com
Mon Mar 20 23:21:25 CET 2006


(Regarding changes caused by ssize_t0

Martin v. Löwis wrote:
> It is possible to look at the changed APIs, see

> http://docs.python.org/dev/api/sequence.html

I think the problem is more with APIs that are not part of the
sequence page.  For instance, in

    http://mail.python.org/pipermail/python-dev/2006-March/062679.html

M.-A. Lemburg mentioned

  PyAPI_FUNC(int) PyDict_Next(
      PyObject *mp, Py_ssize_t *pos, PyObject **key, PyObject **value);

PyDict_Next  isn't on the sequence page, but if you call it, it could
write a Py_ssize_t into pos, even though your pointer is only
large enough for an int.

To do things correctly, you really have to change your call to the
new version (and add the #ifdef)

  #if PY_VERSION_HEX < 0x02050000
  typedef int Py_ssize_t;
  #endif

You can downcast if you aren't ready to support 64-bits, but ... setting
up a possible buffer overflow is a bit worse than simply not supporting.

-jJ


More information about the Python-Dev mailing list