Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b729a1d

Browse files
committed
Patch by Andrew Kuchling to unflush() (flush() for deflating).
Without this, if inflate() returned Z_BUF_ERROR asking for more output space, we would report the error; now, we increase the buffer size and try again, just as for Z_OK.
1 parent 052364b commit b729a1d

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

Modules/zlibmodule.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
#endif
1818
#define DEF_WBITS MAX_WBITS
1919

20-
/* The output buffer will be increased in chunks of ADDCHUNK bytes. */
21-
#define DEFAULTALLOC 16*1024
20+
/* The output buffer will be increased in chunks of DEFAULTALLOC bytes. */
21+
#define DEFAULTALLOC (16*1024)
2222
#define PyInit_zlib initzlib
2323

2424
staticforward PyTypeObject Comptype;
@@ -643,11 +643,14 @@ PyZlib_unflush(self, args)
643643
self->zst.next_out = (unsigned char *)PyString_AsString(RetVal);
644644
length = self->zst.avail_out = DEFAULTALLOC;
645645

646+
/* I suspect that Z_BUF_ERROR is the only error code we need to check for
647+
in the following loop, but will leave the Z_OK in for now to avoid
648+
destabilizing this function. --amk */
646649
err = Z_OK;
647-
while (err == Z_OK)
650+
while ( err == Z_OK )
648651
{
649652
err = inflate(&(self->zst), Z_FINISH);
650-
if (err == Z_OK && self->zst.avail_out == 0)
653+
if ( ( err == Z_OK || err == Z_BUF_ERROR ) && self->zst.avail_out == 0)
651654
{
652655
if (_PyString_Resize(&RetVal, length << 1) == -1)
653656
{
@@ -658,6 +661,7 @@ PyZlib_unflush(self, args)
658661
self->zst.next_out = (unsigned char *)PyString_AsString(RetVal) + length;
659662
self->zst.avail_out = length;
660663
length = length << 1;
664+
err = Z_OK;
661665
}
662666
}
663667
if (err!=Z_STREAM_END)

0 commit comments

Comments
 (0)