Title: Segfault when using re.finditer over mmap
Type: crash Stage:
Components: Versions: Python 2.7
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: alex, benjamin.peterson, fijall, mrabarnett, python-dev, skrah
Priority: normal Keywords:

Created on 2012-03-06 18:00 by fijall, last changed 2012-03-07 21:01 by benjamin.peterson. This issue is now closed.

File name Uploaded Description Edit fijall, 2012-03-06 18:00
Messages (5)
msg155028 - (view) Author: Maciej Fijalkowski (fijall) * (Python committer) Date: 2012-03-06 18:00
Example to get a segfault attached. Crashes under python3 as well.
msg155033 - (view) Author: Matthew Barnett (mrabarnett) * (Python triager) Date: 2012-03-06 19:09
It segfaults because it attempts to access the buffer of an mmap that has been closed. It would be certainly be more friendly if it checked whether the mmap was still open and, if not, raised an exception instead.
msg155105 - (view) Author: Matthew Barnett (mrabarnett) * (Python triager) Date: 2012-03-07 18:58
In the function "getstring" in _sre.c, the code obtains a pointer to the characters of the buffer and then releases the buffer.

There's a comment before the release:

    /* Release the buffer immediately --- possibly dangerous
       but doing something else would require some re-factoring

What's happening is that after the mmap is closed the pointer is no longer valid.
msg155121 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2012-03-07 20:59
New changeset 10a79a33d09b by Benjamin Peterson in branch '3.2':
keep the buffer object around while we're using it (closes #14212)

New changeset 17dfe24e5107 by Benjamin Peterson in branch 'default':
merge 3.2 (#14212)
msg155122 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2012-03-07 21:00
I think 2.7 might be hopeless.
Date User Action Args
2013-08-05 13:08:04serhiy.storchakalinkissue13083 superseder
2012-03-07 21:01:36benjamin.petersonsetstatus: open -> closed
resolution: fixed
2012-03-07 21:00:15benjamin.petersonsetstatus: closed -> open

nosy: + benjamin.peterson
messages: + msg155122

resolution: fixed -> (no value)
stage: resolved ->
2012-03-07 20:59:27python-devsetstatus: open -> closed

nosy: + python-dev
messages: + msg155121

resolution: fixed
stage: resolved
2012-03-07 19:23:17skrahsetnosy: + skrah
2012-03-07 19:01:36alexsetnosy: + alex
2012-03-07 18:58:12mrabarnettsetmessages: + msg155105
2012-03-06 19:09:31mrabarnettsetnosy: + mrabarnett
messages: + msg155033
2012-03-06 18:00:15fijallcreate