This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author neologix
Recipients anglocelt, elachuni, marcio, mcicogni, neologix, r.david.murray, taukki, trogdorsey, vila
Date 2010-04-03.13:39:14
SpamBayes Score 5.551115e-17
Marked as misclassified No
Message-id <1270301956.96.0.536341826844.issue1441530@psf.upfronthosting.co.za>
In-reply-to
Content
$ cat /tmp/test.py
import socket

SIZE = 1000000000L

s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)

try:
    s.recv(SIZE)
finally:
    s.close()

$ python /tmp/test.py
Traceback (most recent call last):
  File "/tmp/test.py", line 8, in <module>
    s.recv(SIZE)
MemoryError

$ strace python /tmp/test.py
[...]
socket(PF_INET, SOCK_DGRAM, IPPROTO_IP) = 3
mmap2(NULL, 1000001536, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = -1 ENOMEM (Cannot allocate memory)
brk(0x4440c000)                         = 0x8a56000
mmap2(NULL, 1000132608, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = -1 ENOMEM (Cannot allocate memory)
mmap2(NULL, 2097152, PROT_NONE, MAP_PRIVATE|MAP_ANONYMOUS|MAP_NORESERVE, -1, 0) = 0xb79b1000
munmap(0xb79b1000, 323584)              = 0
munmap(0xb7b00000, 724992)              = 0
mprotect(0xb7a00000, 135168, PROT_READ|PROT_WRITE) = 0
mmap2(NULL, 1000001536, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = -1 ENOMEM (Cannot allocate memory)
[...]

imaplib is simply requesting too much at a time: the memory error is probably raised in Modules/socketmodule.c:sock_recv
        /* Allocate a new string. */
        buf = PyString_FromStringAndSize((char *) 0, recvlen);
        if (buf == NULL)
                return NULL;

Requesting a 10M read is indeed quite questionable, and will fail no matter what system is used (the limit will depend on the heap usage and OS, though).
The fix should be made at imaplib level, rather than requiring users to redefine IMAP4 read method. A patch is attached (imaplib_read.diff).
History
Date User Action Args
2010-04-03 13:39:17neologixsetrecipients: + neologix, mcicogni, taukki, vila, elachuni, anglocelt, r.david.murray, marcio, trogdorsey
2010-04-03 13:39:16neologixsetmessageid: <1270301956.96.0.536341826844.issue1441530@psf.upfronthosting.co.za>
2010-04-03 13:39:15neologixlinkissue1441530 messages
2010-04-03 13:39:14neologixcreate