[New-bugs-announce] [issue23796] BufferedReader.peek() crashes if closed

Martin Panter report at bugs.python.org
Sat Mar 28 01:29:50 CET 2015

New submission from Martin Panter:

If the BufferedReader object has already been closed, calling peek() can cause a strange error message or a crash:

$ python3 -bWall
Python 3.4.2 (default, Oct  8 2014, 14:33:30) 
[GCC 4.9.1 20140903 (prerelease)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from io import *
>>> b = BufferedReader(BytesIO())
>>> b.close()
>>> b.peek()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: PyMemoryView_FromBuffer(): info->buf must not be NULL
>>> b = BufferedReader(BytesIO(b"12"))
>>> b.read(1)
>>> b.close()
>>> b.peek()
Segmentation fault (core dumped)
[Exit 139]

I’m not able to check with 3.5 at the moment, but looking at the code, I suspect this also applies to 3.5 and there needs to be a CHECK_CLOSED() call added somewhere around Modules/_io/bufferedio.c:884.

components: IO
messages: 239445
nosy: vadmium
priority: normal
severity: normal
status: open
title: BufferedReader.peek() crashes if closed
type: crash
versions: Python 3.4, Python 3.5

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list