php.net |  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
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: j7ur8 at qq dot com
New email:
PHP Version: OS:

 

 [2020-04-11 15:11 UTC] j7ur8 at qq dot com
Description:
------------
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:
---------------
<?php
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.

Patches

Pull Requests

Pull requests:

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2020-04-11 15:22 UTC] peehaa@php.net
According to the docs https://www.php.net/manual/en/wrappers.data.php#refsect1-wrappers.data-options 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] cmb@php.net
-Status: Open +Status: Verified -Type: Bug +Type: Documentation Problem
 [2020-04-11 15:49 UTC] cmb@php.net
It seems the docs are wrong: <https://3v4l.org/9HKq6>.
 [2020-04-11 16:13 UTC] j7ur8 at qq dot com
but it dont create a file.
 [2020-04-11 17:50 UTC] peehaa@php.net
Why would it create a file?
 [2020-04-15 10:28 UTC] nikic@php.net
Looks like internally data stream uses temp stream: https://github.com/php/php-src/blob/99084262c3f56dd8a4efa6fa689441966745440f/main/streams/memory.c#L622

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] cmb@php.net
The following pull request has been associated:

Patch Name: Fix #79467: data:// wrappers are writable
On GitHub:  https://github.com/php/php-src/pull/5511
Patch:      https://github.com/php/php-src/pull/5511.patch
 [2020-05-03 10:18 UTC] cmb@php.net
-Type: Documentation Problem +Type: Bug -Assigned To: +Assigned To: cmb
 [2020-05-03 10:18 UTC] cmb@php.net
Re-classifying as bug according to @nikic's comment above.
 [2020-05-03 10:19 UTC] cmb@php.net
-Summary: file_put_contents can't create file with data:// wrappers +Summary: data:// wrappers are writable
 [2020-05-03 10:19 UTC] cmb@php.net
Automatic comment on behalf of cmbecker69@gmx.de
Revision: http://git.php.net/?p=php-src.git;a=commit;h=69888c3ff1f2301ead8e37b23ff8481d475e29d2
Log: Fix #79467: data:// wrappers are writable
 [2020-05-03 10:19 UTC] cmb@php.net
-Status: Verified +Status: Closed
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Dec 03 17:01:29 2024 UTC