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