diff --git a/ext/standard/tests/file/gh25232.phpt b/ext/standard/tests/file/gh25232.phpt new file mode 100644 index 000000000000..d24064581fd2 --- /dev/null +++ b/ext/standard/tests/file/gh25232.phpt @@ -0,0 +1,30 @@ +--TEST-- +GH-25232: ftruncate() does not invalidate stat cache +--FILE-- +ftruncate(1)); +var_dump(filesize($file)); +?> +--CLEAN-- + +--EXPECT-- +int(8) +bool(true) +int(3) +int(3) +bool(true) +int(1) diff --git a/main/streams/plain_wrapper.c b/main/streams/plain_wrapper.c index b6c117c52e20..00360688be3a 100644 --- a/main/streams/plain_wrapper.c +++ b/main/streams/plain_wrapper.c @@ -1018,10 +1018,16 @@ static int php_stdiop_set_option(php_stream *stream, int option, int value, void if (!SetFilePointerEx(h, old_sz, NULL, FILE_BEGIN)) { return PHP_STREAM_OPTION_RETURN_ERR; } - return PHP_STREAM_OPTION_RETURN_OK; #else - return ftruncate(fd, new_size) == 0 ? PHP_STREAM_OPTION_RETURN_OK : PHP_STREAM_OPTION_RETURN_ERR; + if (ftruncate(fd, new_size) != 0) { + return PHP_STREAM_OPTION_RETURN_ERR; + } #endif + if (EG(active)) { + /* clear stat cache as size, mtime and ctime got changed */ + php_clear_stat_cache(0, NULL, 0); + } + return PHP_STREAM_OPTION_RETURN_OK; } } return PHP_STREAM_OPTION_RETURN_NOTIMPL;