classification
Title: PyBuffer_ToContiguous() off-by-one error for non-contiguous buffers
Type: behavior Stage: resolved
Components: Interpreter Core Versions: Python 2.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: python-dev, rhansen, skrah
Priority: normal Keywords: patch

Created on 2015-01-30 01:07 by rhansen, last changed 2015-01-31 14:26 by skrah. This issue is now closed.

Files
File name Uploaded Description Edit
PyBuffer_ToContiguous.patch rhansen, 2015-01-30 01:07 patch that fixes this bug
issue23349-2.diff skrah, 2015-01-30 17:20
Messages (4)
msg235011 - (view) Author: Richard Hansen (rhansen) * Date: 2015-01-30 01:07
PyBuffer_ToContiguous() has an off-by-one error when copying a buffer it thinks is non-contiguous.

To reproduce, put the following in foo.pyx and compile with Cython v0.21.2:

    cpdef foo():
        cdef unsigned char[:] v = bytearray("testing")
        print repr(memoryview(v).tobytes())

>>> import foo
>>> foo.foo()
'estingt'

(This issue was fixed for Python 3.x in issue #12834 but it was not fixed for Python 2.7.)
msg235042 - (view) Author: Stefan Krah (skrah) * (Python committer) Date: 2015-01-30 17:20
Looks good, here's a patch with tests.
msg235048 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2015-01-30 19:11
New changeset a9305102c892 by Stefan Krah in branch '2.7':
Issue #23349: Fix off-by-one error in PyBuffer_ToContiguous(). Initial patch
https://hg.python.org/cpython/rev/a9305102c892
msg235109 - (view) Author: Stefan Krah (skrah) * (Python committer) Date: 2015-01-31 14:26
Should be fixed, thanks for the patch.
History
Date User Action Args
2015-01-31 14:26:07skrahsetstatus: open -> closed
resolution: fixed
messages: + msg235109

stage: resolved
2015-01-30 19:11:50python-devsetnosy: + python-dev
messages: + msg235048
2015-01-30 17:20:18skrahsetfiles: + issue23349-2.diff

messages: + msg235042
2015-01-30 14:35:07skrahsetnosy: + skrah
2015-01-30 06:30:12rhansensettitle: memoryview.to_bytes() and PyBuffer_ToContiguous() off-by-one error for non-contiguous buffers -> PyBuffer_ToContiguous() off-by-one error for non-contiguous buffers
2015-01-30 01:07:08rhansencreate