Title: bz2 iterator fails silently on MemoryError
Type: behavior Stage:
Components: Extension Modules Versions:
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: mdehoon, pitrou
Priority: normal Keywords: patch

Created on 2008-06-26 09:08 by mdehoon, last changed 2008-08-09 17:22 by pitrou. This issue is now closed.

File name Uploaded Description Edit
bz2module.c.patch mdehoon, 2008-06-26 09:08 Patch to Modules/bz2module.c
Messages (2)
msg68770 - (view) Author: Michiel de Hoon (mdehoon) * Date: 2008-06-26 09:08
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.
msg70939 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2008-08-09 17:22
Fixed in r65609. Thanks for the report and for the patch!
Date User Action Args
2008-08-09 17:22:54pitrousetstatus: open -> closed
resolution: fixed
messages: + msg70939
nosy: + pitrou
2008-06-26 09:08:20mdehooncreate