[Python-bugs-list] [ python-Bugs-640230 ] Discovered typo in zlib test.

noreply@sourceforge.net noreply@sourceforge.net
Tue, 19 Nov 2002 13:40:11 -0800


Bugs item #640230, was opened at 2002-11-18 18:36
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=640230&group_id=5470

Category: None
Group: None
Status: Open
Resolution: None
Priority: 6
Submitted By: Scott David Daniels (scott_daniels)
Assigned to: Nobody/Anonymous (nobody)
Summary: Discovered typo in zlib test.

Initial Comment:
In test_zlib.py (while chasing what appears to be a
documentation problem), I found a flaw in the code
that tests max_length limitted output from a 
decompression object test.

Starting at line 100, the existing code is:
...
bufs.append(deco.flush())
decomp2 = ''.join(buf)
if decomp2 != buf:
    print "max_length decompressobj failed"
else:
    print "max_length decompressobj succeeded"
...

This test will always succeed (''.join(str) == str).

What seems obviously meant is:
...
bufs.append(deco.flush())
decomp2 = ''.join(bufs)
if decomp2 != buf:
    print "max_length decompressobj failed"
else:
    print "max_length decompressobj succeeded"
...



----------------------------------------------------------------------

>Comment By: Scott David Daniels (scott_daniels)
Date: 2002-11-19 21:40

Message:
Logged In: YES 
user_id=493818

OK, The reason the code fails after the fix is as follows:
deco.flush() does not return any output.
The loop control says, "while we have more unexamined 
source."

However, the decompressor can consume all of the input 
before it has provided all of its output.  So, there are two 
possible fixes:

1) Minimal change:  Change the loop control to say, in 
effect, "While we have more input or are producing output.":
Around line 92:
Change:
    bufs = []
    while cb:
        max_length = 1 + len(cb)/10
To:
    bufs = []
    while cb or chunk:
        max_length = 1 + len(cb)/10


2) More reasonable(?) change:  After the insertion loop, (just 
before the flush) extract all remaining output:
Around line 99:
        cb = deco.unconsumed_tail
    bufs.append(deco.flush())
    decomp2 = ''.join(bufs)
Becomes:
        cb = deco.unconsumed_tail
    while bufs[-1]:
        bufs.append(deco.decompress('', max_length))
    bufs.append(deco.flush())
    decomp2 = ''.join(bufs)


---
Note, in any case, the
    bufs.append(deco.flush())
originally on line 100 _always_ appends a zero-length string.
I would suggest changing it to simply:
    deco.flush()

    

----------------------------------------------------------------------

Comment By: Michael Hudson (mwh)
Date: 2002-11-19 09:50

Message:
Logged In: YES 
user_id=6656

Assuming Tim meant what he said, not what he did: raising
priority.

----------------------------------------------------------------------

Comment By: Tim Peters (tim_one)
Date: 2002-11-18 20:56

Message:
Logged In: YES 
user_id=31435

Good eye!  Unfortunately, when I repair that, the test fails 
here -- decomp2 is a proper prefix of buf then.  It's "too 
short".  Raised priority but left unassigned (someone who 
understands zlib better will have to jump in).

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=640230&group_id=5470