@@ -27,7 +27,7 @@ typedef struct _php_zlib_filter_data {
27
27
unsigned char * outbuf ;
28
28
size_t outbuf_len ;
29
29
int persistent ;
30
- zend_bool finished ;
30
+ zend_bool finished ; /* for zlib.deflate: signals that no flush is pending */
31
31
} php_zlib_filter_data ;
32
32
33
33
/* }}} */
@@ -195,14 +195,18 @@ static php_stream_filter_status_t php_zlib_deflate_filter(
195
195
bucket = php_stream_bucket_make_writeable (bucket );
196
196
197
197
while (bin < (unsigned int ) bucket -> buflen ) {
198
+ int flush_mode ;
199
+
198
200
desired = bucket -> buflen - bin ;
199
201
if (desired > data -> inbuf_len ) {
200
202
desired = data -> inbuf_len ;
201
203
}
202
204
memcpy (data -> strm .next_in , bucket -> buf + bin , desired );
203
205
data -> strm .avail_in = desired ;
204
206
205
- status = deflate (& (data -> strm ), flags & PSFS_FLAG_FLUSH_CLOSE ? Z_FULL_FLUSH : (flags & PSFS_FLAG_FLUSH_INC ? Z_SYNC_FLUSH : Z_NO_FLUSH ));
207
+ flush_mode = flags & PSFS_FLAG_FLUSH_CLOSE ? Z_FULL_FLUSH : (flags & PSFS_FLAG_FLUSH_INC ? Z_SYNC_FLUSH : Z_NO_FLUSH );
208
+ data -> finished = flush_mode != Z_NO_FLUSH ;
209
+ status = deflate (& (data -> strm ), flush_mode );
206
210
if (status != Z_OK ) {
207
211
/* Something bad happened */
208
212
php_stream_bucket_delref (bucket );
@@ -229,11 +233,12 @@ static php_stream_filter_status_t php_zlib_deflate_filter(
229
233
php_stream_bucket_delref (bucket );
230
234
}
231
235
232
- if (flags & PSFS_FLAG_FLUSH_CLOSE ) {
236
+ if (flags & PSFS_FLAG_FLUSH_CLOSE || (( flags & PSFS_FLAG_FLUSH_INC ) && ! data -> finished ) ) {
233
237
/* Spit it out! */
234
238
status = Z_OK ;
235
239
while (status == Z_OK ) {
236
- status = deflate (& (data -> strm ), Z_FINISH );
240
+ status = deflate (& (data -> strm ), (flags & PSFS_FLAG_FLUSH_CLOSE ? Z_FINISH : Z_SYNC_FLUSH ));
241
+ data -> finished = 1 ;
237
242
if (data -> strm .avail_out < data -> outbuf_len ) {
238
243
size_t bucketlen = data -> outbuf_len - data -> strm .avail_out ;
239
244
@@ -394,6 +399,7 @@ static php_stream_filter *php_zlib_filter_create(const char *filtername, zval *f
394
399
}
395
400
}
396
401
status = deflateInit2 (& (data -> strm ), level , Z_DEFLATED , windowBits , memLevel , 0 );
402
+ data -> finished = 1 ;
397
403
fops = & php_zlib_deflate_ops ;
398
404
} else {
399
405
status = Z_DATA_ERROR ;
0 commit comments