[New-bugs-announce] [issue23352] PyBuffer_IsContiguous() sometimes returns wrong result if suboffsets != NULL

Richard Hansen report at bugs.python.org
Fri Jan 30 02:33:45 CET 2015


New submission from Richard Hansen:

According to https://docs.python.org/2/c-api/buffer.html#the-new-style-py-buffer-struct if the suboffsets member of Py_buffer is non-NULL and all members of the array are negative, the buffer may be contiguous.

PyBuffer_IsContiguous() does not behave this way.  It assumes that if the suboffsets member is non-NULL then at least one member of the array is non-negative, and thus assumes that the buffer is non-contiguous.  This is not always correct.

One consequence of this bug is PyBuffer_ToContiguous() (and thus memoryview.tobytes()) falls back to slow (and currently buggy, see issue #23349) memory copying code.

Attached is a patch that fixes this bug.  The patch is against 2.7 but can be trivially modified to apply to 3.x.

----------
components: Interpreter Core
files: PyBuffer_IsContiguous.patch
keywords: patch
messages: 235014
nosy: rhansen
priority: normal
severity: normal
status: open
title: PyBuffer_IsContiguous() sometimes returns wrong result if suboffsets != NULL
versions: Python 2.7, Python 3.2, Python 3.3, Python 3.4, Python 3.5, Python 3.6
Added file: http://bugs.python.org/file37914/PyBuffer_IsContiguous.patch

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue23352>
_______________________________________


More information about the New-bugs-announce mailing list