Stdlib: touch() mtime/atime visible without prior stat (#28995) - #29011
Merged
Conversation
VmFsTouchPure used VmStatPath::exists(), which wrote a positive VmStatCache hit before host utime — so the first filemtime/fileatime after a timed touch returned "now". Probe via uncached VmStatNative::stat and clear only the host BG cache after a successful touch; keep VmStatCache positive hits until clearstatcache (#25853).
3 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
touch($path, $mtime[, $atime])so the firstfilemtime/fileatimeafter a timed touch matches Zend when there was no prior positive stat cache hit (Stdlib: touch() ignores $mtime/$atime — always uses now (ext/standard/filestat.c) #28995).VmFsTouchPureusedVmStatPath::exists()→VmStatCache::stat(), poisoning a positive “now” hit before hostutime;invalidateNegativeleft that hit in place.VmStatNative::stat, and clear only the host BG stat cache after a successful hosttouch— do not dropVmStatCachepositive entries (php-src-strict#25853).is_file/filemtime, eitherclearstatcacheor use a fresh path before asserting new times; addtouch_mtime_atime_no_prior_stat.phpt.php-src:
ext/standard/filestat.c—PHP_FUNCTION(touch)/php_touchTest plan
php bin/vm.php test/compliance/cases/stdlib/touch.phptphp bin/vm.php test/compliance/cases/stdlib/touch_mtime_atime_no_prior_stat.phptphp bin/vm.php test/compliance/cases/stdlib/touch_statcache_stale.phptvendor/bin/phpunit --filter 'TouchBuiltinTest::testVm|VmFsTouchTempnam|VmStatCacheTest::testTouch'→ OK (10 tests)AOT note: native AOT
touchviaFsDirJitHelperstill delegates to host\touch/\fopeninside the compiled helper (#12145) and does not set times on this host (pre-existing; 1-arg create also fails). This PR fixes the VM php-src-strict gap the issue repro targets; AOT utime needs a non-host path (follow-up).Gate snapshot: inventory OK 7248/7248;
north-star5-fastok;user_release_ready: nodue to 30 stale helper-runtime units (#29003 / open PR #29005) — unrelated to this change.Closes #28995
Made with Cursor