classification
Title: _sre: getstring() releases the buffer before using it
Type: Stage: resolved
Components: Library (Lib), Regular Expressions Versions: Python 3.3, Python 3.4
process
Status: closed Resolution: duplicate
Dependencies: Superseder: Segfault when using re.finditer over mmap
View: 14212
Assigned To: Nosy List: ezio.melotti, mrabarnett, pitrou, serhiy.storchaka, vstinner
Priority: normal Keywords:

Created on 2011-10-01 01:50 by vstinner, last changed 2013-08-05 13:08 by serhiy.storchaka. This issue is now closed.

Messages (3)
msg144714 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2011-10-01 01:50
getstring() of the _sre module contains the following code:
-------------
    ...
    buffer = Py_TYPE(string)->tp_as_buffer;
    if (!buffer || !buffer->bf_getbuffer ||
        (*buffer->bf_getbuffer)(string, &view, PyBUF_SIMPLE) < 0) {
            PyErr_SetString(PyExc_TypeError, "expected string or buffer");
            return NULL;
    }

    /* determine buffer size */
    bytes = view.len;
    ptr = view.buf;

    /* Release the buffer immediately --- possibly dangerous
       but doing something else would require some re-factoring
    */
    PyBuffer_Release(&view);
    ...
-------------

getstring() is used to initialize a state or a pattern. State and pattern have destructors (pattern_dealloc() and state_fini()), so it should be possible to keep the view active and call PyBuffer_Release() in the destructor.
msg193237 - (view) Author: Matthew Barnett (mrabarnett) * (Python triager) Date: 2013-07-17 15:57
It looks like this was fixed for issue #14212.
msg194475 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2013-08-05 13:08
Agree.
History
Date User Action Args
2013-08-05 13:08:38serhiy.storchakasetmessages: + msg194475
2013-08-05 13:08:04serhiy.storchakasetstatus: open -> closed
superseder: Segfault when using re.finditer over mmap
resolution: duplicate
stage: resolved
2013-07-17 15:57:25mrabarnettsetmessages: + msg193237
2013-07-17 08:32:43serhiy.storchakasetnosy: + ezio.melotti, serhiy.storchaka, mrabarnett

components: + Regular Expressions
versions: + Python 3.4
2011-10-01 01:50:50vstinnercreate