@@ -631,6 +631,12 @@ PHPAPI zend_result _php_stream_fill_read_buffer(php_stream *stream, size_t size)
631631 /* when a filter needs feeding, there is no brig_out to deal with.
632632 * we simply continue the loop; if the caller needs more data,
633633 * we will read again, otherwise out job is done here */
634+
635+ /* Filter could have added buckets anyway, but signalled that it did not return any. Discard them. */
636+ while ((bucket = brig_outp -> head )) {
637+ php_stream_bucket_unlink (bucket );
638+ php_stream_bucket_delref (bucket );
639+ }
634640 break ;
635641
636642 case PSFS_ERR_FATAL :
@@ -1264,14 +1270,22 @@ static ssize_t _php_stream_write_filtered(php_stream *stream, const char *buf, s
12641270 php_stream_bucket_delref (bucket );
12651271 }
12661272 break ;
1267- case PSFS_FEED_ME :
1268- /* need more data before we can push data through to the stream */
1269- break ;
12701273
12711274 case PSFS_ERR_FATAL :
12721275 /* some fatal error. Theoretically, the stream is borked, so all
12731276 * further writes should fail. */
1274- return (ssize_t ) -1 ;
1277+ consumed = (ssize_t ) -1 ;
1278+ ZEND_FALLTHROUGH ;
1279+
1280+ case PSFS_FEED_ME :
1281+ /* need more data before we can push data through to the stream */
1282+ /* Filter could have added buckets anyway, but signalled that it did not return any. Discard them. */
1283+ while (brig_inp -> head ) {
1284+ bucket = brig_inp -> head ;
1285+ php_stream_bucket_unlink (bucket );
1286+ php_stream_bucket_delref (bucket );
1287+ }
1288+ break ;
12751289 }
12761290
12771291 return consumed ;
0 commit comments