René's URL Explorer Experiment


Title: file_put_contents() is racy · Issue #20108 · php/php-src · GitHub

Open Graph Title: file_put_contents() is racy · Issue #20108 · php/php-src

X Title: file_put_contents() is racy · Issue #20108 · php/php-src

Description: php-src/ext/standard/file.c Line 492 in 18d99ee php_stream_truncate_set_size(stream, 0); Imagine following sequence (two processes A and B writing some serialized data to file called "cache.dat" using file_put_contents(): Process A: open...

Open Graph Description: php-src/ext/standard/file.c Line 492 in 18d99ee php_stream_truncate_set_size(stream, 0); Imagine following sequence (two processes A and B writing some serialized data to file called "cache.dat" us...

X Description: php-src/ext/standard/file.c Line 492 in 18d99ee php_stream_truncate_set_size(stream, 0); Imagine following sequence (two processes A and B writing some serialized data to file called "cache.da...

Opengraph URL: https://github.com/php/php-src/issues/20108

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"file_put_contents() is racy","articleBody":"https://github.com/php/php-src/blob/18d99ee4b724f9ecd18122abacfac5767bfbfb48/ext/standard/file.c#L492\n\nImagine following sequence (two processes A and B writing some serialized data to file called \"cache.dat\" using file_put_contents():\n\n- Process A: open the cache file for writing\n- Process B: open the same cache file for writing\n- Process A: truncate the file to zero length\n- Process B: truncate the file to zero length\n- Process A: write the cached data (e.g. 1002 byte long serialized data)\n- Process B: write the cached data (e.g. 1000 byte long serialized data)\n- Process A: close the file\n- Procees B: close the file\n\nThis results in a file with 1000 bytes from Process B and 2 extra bytes from process A and you end up with `unserialize(): Extra data starting at offset 1000 of 1002 bytes` if you later try to unserialize the file.\n\nSince it seems that many developers incorrectly believe that a function called file_put_contents() would actually write a file with the given contents, I'm suggesting that PHP internal implementation should instead be (unless FILE_APPEND or LOCK_EX in flags)\n\n1. Create a new temporary file in the same directory with the target filename.\n2. Write the given data (argument to file_put_contents()) into said file.\n3. Close the file\n4. Rename the temporary file to final target filename.\n\nSince only the rename() is guaranteed to be atomic in POSIX compatible systems (and even that requires rename within the same directory), this is the only way to make sure you don't end up with mixture of two files when multiple processes are calling file_put_contents() at nearly the same time. And in case NFS is used, you cannot assume that LOCK_EX actually works so you must use rename() semantics.\n\nAnd maybe allow current behavior with some new flag (`FILE_ALLOW_RACY`?) with documentation \"Reduce syscalls to improve performance but caller must guarantee that two processes are not trying to write into the same file concurrently.\"","author":{"url":"https://github.com/mikkorantalainen","@type":"Person","name":"mikkorantalainen"},"datePublished":"2025-10-08T15:30:28Z","url":"https://github.com/php/php-src/issues/20108"}

react-profiling0
react-import-mapreact,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322
route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:63256362-51e9-9f00-e67d-455d6a347311
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idAF1A:2F85FF:2BDCBB:399340:6AFE5C58
html-safe-nonce6f5f433f73c1e5f064eb6fecaad8de31b9d09e577987fc36ce78e71f7ac541cc
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBRjFBOjJGODVGRjoyQkRDQkI6Mzk5MzQwOjZBRkU1QzU4IiwidmlzaXRvcl9pZCI6IjgyMTQ3NjQ2OTkzNjM3Mjg0NzIiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ==
visitor-hmac7edc7b9e2632af0f92098f5f0bac4a75a5b0fab3dfe2a9b847db76b78cede32d
hovercard-subject-tagissue:3495934439
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/php/php-src/20108/issue_layout
twitter:imagehttps://opengraph.githubassets.com/7783fc6e9f6cc5266f947ad526b556af970a6f190f463b049359cc7182a4c926/php/php-src/issues/20108
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/7783fc6e9f6cc5266f947ad526b556af970a6f190f463b049359cc7182a4c926/php/php-src/issues/20108
og:image:altphp-src/ext/standard/file.c Line 492 in 18d99ee php_stream_truncate_set_size(stream, 0); Imagine following sequence (two processes A and B writing some serialized data to file called "cache.dat" us...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamemikkorantalainen
hostnamegithub.com
expected-hostnamegithub.com
Noneb3c0f155eafc27e60db6e254d1ffff0e072e9ab3b4018a5ee518797c19d89f86
turbo-cache-controlno-preview
go-importgithub.com/php/php-src git https://github.com/php/php-src.git
octolytics-dimension-user_id25158
octolytics-dimension-user_loginphp
octolytics-dimension-repository_id1903522
octolytics-dimension-repository_nwophp/php-src
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id1903522
octolytics-dimension-repository_network_root_nwophp/php-src
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release4a10310af51a1bfffbedc4fd81cb582acf0cb0ff
ui-targetfull
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/php/php-src/issues/20108#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fphp%2Fphp-src%2Fissues%2F20108
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://github.com/security/advanced-security
Copilot for businessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fphp%2Fphp-src%2Fissues%2F20108
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=php%2Fphp-src
Reloadhttps://github.com/php/php-src/issues/20108
Reloadhttps://github.com/php/php-src/issues/20108
Reloadhttps://github.com/php/php-src/issues/20108
phphttps://github.com/php
php-srchttps://github.com/php/php-src
Codehttps://github.com/php/php-src
Issues1k (1k)https://github.com/php/php-src/issues
Pull requests1.3k (1.3k)https://github.com/php/php-src/pulls
Actionshttps://github.com/php/php-src/actions
Security and quality66 (66)https://github.com/php/php-src/security
Insightshttps://github.com/php/php-src/insights
https://github.com/php/php-src
New issuehttps://github.com/login?return_to=https://github.com/php/php-src/issues/20108
New issuehttps://github.com/login?return_to=https://github.com/php/php-src/issues/20108
file_put_contents() is racyhttps://github.com/php/php-src/issues/20108#top
https://github.com/mikkorantalainen
mikkorantalainenhttps://github.com/mikkorantalainen
on Oct 8, 2025https://github.com/php/php-src/issues/20108#issue-3495934439
php-src/ext/standard/file.chttps://github.com/php/php-src/blob/18d99ee4b724f9ecd18122abacfac5767bfbfb48/ext/standard/file.c#L492
18d99eehttps://github.com/php/php-src/commit/18d99ee4b724f9ecd18122abacfac5767bfbfb48
https://github.com/iluuu1994
iluuu1994https://github.com/iluuu1994
on Oct 9, 2025https://github.com/php/php-src/issues/20108#issuecomment-3386756154
@bukkahttps://github.com/bukka
https://github.com/mikkorantalainen
mikkorantalainenhttps://github.com/mikkorantalainen
on Oct 22, 2025https://github.com/php/php-src/issues/20108#issuecomment-3431734733
https://github.com/mikkorantalainen
mikkorantalainenhttps://github.com/mikkorantalainen
on Oct 22, 2025https://github.com/php/php-src/issues/20108#issuecomment-3431907609
https://github.com/jeffdafoe
jeffdafoehttps://github.com/jeffdafoe
on Oct 22, 2025https://github.com/php/php-src/issues/20108#issuecomment-3433211438
https://github.com/iluuu1994
iluuu1994https://github.com/iluuu1994
on Oct 22, 2025https://github.com/php/php-src/issues/20108#issuecomment-3434480345
5e9e9c9https://github.com/php/php-src/commit/5e9e9c9d511866af8b6c6d336222a570e6ba5f62
https://github.com/jeffdafoe
jeffdafoehttps://github.com/jeffdafoe
on Oct 23, 2025https://github.com/php/php-src/issues/20108#issuecomment-3437940196
https://github.com/iluuu1994
iluuu1994https://github.com/iluuu1994
on Oct 23, 2025https://github.com/php/php-src/issues/20108#issuecomment-3438592819
https://github.com/dktapps
dktappshttps://github.com/dktapps
on Nov 8, 2025https://github.com/php/php-src/issues/20108#issuecomment-3505546050
Sign up for freehttps://github.com/signup?return_to=https://github.com/php/php-src/issues/20108
Sign in to commenthttps://github.com/login?return_to=https://github.com/php/php-src/issues/20108
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.