|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #79467 data:// wrappers are writable
Submitted: 2020-04-11 15:11 UTC Modified: 2020-05-03 10:19 UTC
From: j7ur8 at qq dot com Assigned: cmb (profile)
Status: Closed Package: Streams related
PHP Version: 7.4.4 OS: windows Linux
Private report: No CVE-ID: None
 [2020-04-11 15:11 UTC] j7ur8 at qq dot com
file_put_contents ( string $filename , mixed $data [, int $flags = 0 [, resource $context ]] ) : int

1. above is the function details

2. And when the params of `filename` in file_put_contents starts with data:// , php will execute it successful, but create a file.

Test script:
echo file_put_contents('data://text/plain,cccc', 'data');


Expected result:
4 ; and create a file names 'ccc'

Actual result:
4; and do not create any file.


Add a Patch

Pull Requests

Pull requests:

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2020-04-11 15:22 UTC]
According to the docs writing is not supported so seems to be working as designed.

If anything it shouldn't say it wrote 4 bytes instead.
 [2020-04-11 15:49 UTC]
-Status: Open +Status: Verified -Type: Bug +Type: Documentation Problem
 [2020-04-11 15:49 UTC]
It seems the docs are wrong: <>.
 [2020-04-11 16:13 UTC] j7ur8 at qq dot com
but it dont create a file.
 [2020-04-11 17:50 UTC]
Why would it create a file?
 [2020-04-15 10:28 UTC]
Looks like internally data stream uses temp stream:

I do wonder whether it shouldn't be better to drop write support there than to document it, as it doesn't really make sense to me for data streams.
 [2020-05-02 15:39 UTC]
The following pull request has been associated:

Patch Name: Fix #79467: data:// wrappers are writable
On GitHub:
 [2020-05-03 10:18 UTC]
-Type: Documentation Problem +Type: Bug -Assigned To: +Assigned To: cmb
 [2020-05-03 10:18 UTC]
Re-classifying as bug according to @nikic's comment above.
 [2020-05-03 10:19 UTC]
-Summary: file_put_contents can't create file with data:// wrappers +Summary: data:// wrappers are writable
 [2020-05-03 10:19 UTC]
Automatic comment on behalf of
Log: Fix #79467: data:// wrappers are writable
 [2020-05-03 10:19 UTC]
-Status: Verified +Status: Closed
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 18 21:01:29 2024 UTC