@@ -349,14 +349,15 @@ PHPAPI php_stream *_php_stream_fopen_from_pipe(FILE *file, const char *mode STRE
349349static ssize_t php_stdiop_write (php_stream * stream , const char * buf , size_t count )
350350{
351351 php_stdio_stream_data * data = (php_stdio_stream_data * )stream -> abstract ;
352+ ssize_t bytes_written ;
352353
353354 assert (data != NULL );
354355
355356 if (data -> fd >= 0 ) {
356357#ifdef PHP_WIN32
357- ssize_t bytes_written = _write (data -> fd , buf , PLAIN_WRAP_BUF_SIZE (count ));
358+ bytes_written = _write (data -> fd , buf , PLAIN_WRAP_BUF_SIZE (count ));
358359#else
359- ssize_t bytes_written = write (data -> fd , buf , count );
360+ bytes_written = write (data -> fd , buf , count );
360361#endif
361362 if (bytes_written < 0 ) {
362363 if (PHP_IS_TRANSIENT_ERROR (errno )) {
@@ -370,7 +371,6 @@ static ssize_t php_stdiop_write(php_stream *stream, const char *buf, size_t coun
370371 php_error_docref (NULL , E_NOTICE , "Write of %zu bytes failed with errno=%d %s" , count , errno , strerror (errno ));
371372 }
372373 }
373- return bytes_written ;
374374 } else {
375375
376376#ifdef HAVE_FLUSHIO
@@ -380,8 +380,15 @@ static ssize_t php_stdiop_write(php_stream *stream, const char *buf, size_t coun
380380 data -> last_op = 'w' ;
381381#endif
382382
383- return (ssize_t ) fwrite (buf , 1 , count , data -> file );
383+ bytes_written = (ssize_t ) fwrite (buf , 1 , count , data -> file );
384384 }
385+
386+ if (EG (active )) {
387+ /* clear stat cache as mtime and ctime got changed */
388+ php_clear_stat_cache (0 , NULL , 0 );
389+ }
390+
391+ return bytes_written ;
385392}
386393
387394static ssize_t php_stdiop_read (php_stream * stream , char * buf , size_t count )
@@ -460,6 +467,12 @@ static ssize_t php_stdiop_read(php_stream *stream, char *buf, size_t count)
460467
461468 stream -> eof = feof (data -> file );
462469 }
470+
471+ if (EG (active )) {
472+ /* clear stat cache as atime got changed */
473+ php_clear_stat_cache (0 , NULL , 0 );
474+ }
475+
463476 return ret ;
464477}
465478
@@ -540,6 +553,10 @@ static int php_stdiop_flush(php_stream *stream)
540553 * something completely different.
541554 */
542555 if (data -> file ) {
556+ if (EG (active )) {
557+ /* clear stat cache as there might be a write so mtime and ctime might have changed */
558+ php_clear_stat_cache (0 , NULL , 0 );
559+ }
543560 return fflush (data -> file );
544561 }
545562 return 0 ;
@@ -1154,6 +1171,12 @@ PHPAPI php_stream *_php_stream_fopen(const char *filename, const char *mode, zen
11541171 ret = php_stream_fopen_from_fd_rel (fd , mode , persistent_id , (open_flags & O_APPEND ) == 0 );
11551172 }
11561173
1174+ if (EG (active )) {
1175+ /* clear stat cache as mtime and ctime might got changed - phar can use stream before
1176+ * cache is initialized so we need to check if the execution is active. */
1177+ php_clear_stat_cache (0 , NULL , 0 );
1178+ }
1179+
11571180 if (ret ) {
11581181 if (opened_path ) {
11591182 * opened_path = zend_string_init (realpath , strlen (realpath ), 0 );
0 commit comments