stream->readpos = 0;
stream->writepos = 0;
} else if (status == PSFS_PASS_ON) {
- /* Put any filtered data onto the readbuffer stack.
- Previously read data has been at least partially consumed. */
- stream->readpos += consumed;
-
- if (stream->writepos == stream->readpos) {
- /* Entirely consumed */
- stream->writepos = 0;
- stream->readpos = 0;
- }
+ /* If any data is consumed, we cannot rely upon the existing read buffer,
+ as the filtered data must replace the existing data, so invalidate the cache */
+ /* note that changes here should be reflected in
+ main/streams/streams.c::php_stream_fill_read_buffer */
+ stream->writepos = 0;
+ stream->readpos = 0;
while (brig_outp->head) {
bucket = brig_outp->head;
php_stream_bucket_brigade brig_in = { NULL, NULL }, brig_out = { NULL, NULL };
php_stream_bucket_brigade *brig_inp = &brig_in, *brig_outp = &brig_out, *brig_swap;
+ /* Invalidate the existing cache, otherwise reads can fail, see note in
+ main/streams/filter.c::_php_stream_filter_append */
+ stream->writepos = stream->readpos = 0;
+
/* allocate a buffer for reading chunks */
chunk_buf = emalloc(stream->chunk_size);