Small bug in zlib module

Greg Chapman glc at well.com
Tue Jun 6 11:16:05 EDT 2000


Using Python 1.5.2 (under Windows 98), this script causes python to enter a
loop in which it progressively allocates larger and larger blocks of memory:

  import zlib
  s = zlib.decompress("")

I believe the problem is that the inflate function (inside zlib) returns
Z_BUF_ERROR when the z_stream parameter has avail_in == 0.  The avail_in
field is initialized with the length of the input buffer.  In the example
above, this length == 0; thus, inflate will always return Z_BUF_ERROR.
Unfortunately, the PyZlib_decompress function (in zlibmodule.c) treats this
return value as an indication that it needs to increase the size of the
output buffer and retry the inflate function (which will again return
Z_BUF_ERROR).

I assume PyZlib_decompress should have a check for an empty input string and
(if found) should generate an appropriate exception.

Greg Chapman





More information about the Python-list mailing list