[php-src] Issue #25232: ftruncate does not invalidate stat cache
| From: | tolry | Date: | Fri, 06 Nov 2026 07:52:47 +0000 |
| Subject: | [php-src] Issue #25232: ftruncate does not invalidate stat cache | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-254031@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/25232
Author: tolry
### Description
The following code:
ftruncate does not call clearstatcache (or the equivalent C logic),
therefore an explicit call is needed to not get stale information.
```php
<?php
$file = tempnam(sys_get_temp_dir(), 'stat-demo-');
file_put_contents($file, 'abcdefgh');
$handle = fopen($file, 'r+');
var_dump(filesize($file)); // int(8): populates the cache
var_dump(ftruncate($handle, 3)); // bool(true): truncation succeeds
var_dump(filesize($file)); // int(8): stale cached size
clearstatcache();
var_dump(filesize($file)); // int(3): actual size
fclose($handle);
unlink($file);
```
Resulted in this output:
```
int(8)
bool(true)
int(8)
int(3)
```
But I expected this output instead:
```
int(8)
bool(true)
int(3)
int(3)
```
### PHP Version
```plain
PHP 8.5.11 (cli) (built: Sep 24 2026 14:36:15) (NTS)
Copyright (c) The PHP Group
Built by Ubuntu
Zend Engine v4.5.11, Copyright (c) Zend Technologies
with Xdebug v3.5.3, Copyright (c) 2002-2026, by Derick Rethans
with Zend OPcache v8.5.11, Copyright (c), by Zend Technologies
```
### Operating System
Ubuntu 24.04 (in a docker container)