[Python-checkins] CVS: python/dist/src/Lib/test test_zlib.py,1.14,1.15
Jeremy Hylton
jhylton@users.sourceforge.net
Tue, 16 Oct 2001 13:39:51 -0700
Update of /cvsroot/python/python/dist/src/Lib/test
In directory usw-pr-cvs1:/tmp/cvs-serv21328/Lib/test
Modified Files:
test_zlib.py
Log Message:
[ #403753 ] zlib decompress; uncontrollable memory usage
Mostly by Toby Dickenson and Titus Brown.
Add an optional argument to a decompression object's decompress()
method. The argument specifies the maximum length of the return
value. If the uncompressed data exceeds this length, the excess data
is stored as the unconsumed_tail attribute. (Not to be confused with
unused_data, which is a separate issue.)
Difference from SF patch: Default value for unconsumed_tail is ""
rather than None. It's simpler if the attribute is always a string.
Index: test_zlib.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/test_zlib.py,v
retrieving revision 1.14
retrieving revision 1.15
diff -C2 -d -r1.14 -r1.15
*** test_zlib.py 2001/08/10 15:50:11 1.14
--- test_zlib.py 2001/10/16 20:39:49 1.15
***************
*** 77,80 ****
--- 77,110 ----
print "decompressobj with init options succeeded"
+ print "should be '':", `deco.unconsumed_tail`
+
+ # Check a decompression object with max_length specified
+ deco = zlib.decompressobj(-12)
+ cb = combuf
+ bufs = []
+ while cb:
+ max_length = 1 + len(cb)/10
+ chunk = deco.decompress(cb, max_length)
+ if len(chunk) > max_length:
+ print 'chunk too big (%d>%d)' % (len(chunk),max_length)
+ bufs.append(chunk)
+ cb = deco.unconsumed_tail
+ bufs.append(deco.flush())
+ decomp2 = ''.join(buf)
+ if decomp2 != buf:
+ print "max_length decompressobj failed"
+ else:
+ print "max_length decompressobj succeeded"
+
+ # Misc tests of max_length
+ deco = zlib.decompressobj(-12)
+ try:
+ deco.decompress("", -1)
+ except ValueError:
+ pass
+ else:
+ print "failed to raise value error on bad max_length"
+ print "unconsumed_tail should be '':", `deco.unconsumed_tail`
+
# Test flush() with the various options, using all the different levels
# in order to provide more variations.