[New-bugs-announce] [issue3205] bz2 iterator fails silently on MemoryError

Michiel de Hoon report at bugs.python.org
Thu Jun 26 11:08:21 CEST 2008


New submission from Michiel de Hoon <mdehoon at users.sourceforge.net>:

PyMem_Malloc is called in the Util_ReadAhead function in bz2module.c.
The code checks if PyMem_Malloc returns NULL, but in that case no
MemoryError is raised. So, if in the following code:

>>> input = bz2.BZ2File("myfile.txt.bz2")
>>> for line in input:
...     # do something with the line

Python runs out of memory during the for-loop, then the for-loop exits
without an Exception being raised. To the user, it appears that the end
of the myfile.txt.bz2 file was reached and that no error occurred.

In the attached patch, I call PyErr_NoMemory() if PyMem_Malloc fails.
This then raises the MemoryError exception as appropriate.

----------
components: Extension Modules
files: bz2module.c.patch
keywords: patch
messages: 68770
nosy: mdehoon
severity: normal
status: open
title: bz2 iterator fails silently on MemoryError
type: behavior
Added file: http://bugs.python.org/file10740/bz2module.c.patch

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


More information about the New-bugs-announce mailing list