Skip to content

Commit 69888c3

Browse files
committed
Fix #79467: data:// wrappers are writable
Despite the docs claiming that data: wrappers would not be writable[1], they are implemented as writing to a memory stream. That does not seem to be particularly sensible, so we disallow writing altogether. [1] <https://www.php.net/manual/en/wrappers.data.php#refsect1-wrappers.data-options>
1 parent 34f727e commit 69888c3

File tree

4 files changed

+12
-1
lines changed

4 files changed

+12
-1
lines changed

NEWS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ PHP NEWS
2424
(cmb)
2525
. Use SSE2 instructions do locale independent strtolower. (Laruence)
2626
. Fixed bug #79521 (Check __set_state structure). (carusogabriel)
27+
. Fixed bug #79467 (data:// wrappers are writable). (cmb)
2728

2829
- BZ2:
2930
. Fixed bug #71263 (fread() does not report bzip2.decompress errors). (cmb)

UPGRADING

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ PHP 8.0 UPGRADE NOTES
181181
. Disabled functions are now treated exactly like non-existent functions.
182182
Calling a disabled function will report it as unknown, and redefining a
183183
disabled function is now possible.
184+
. data: wrappers are no longer writable, what matches the documented behavior.
184185

185186
- COM:
186187
. Removed the ability to import case-insensitive constants from type
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
--TEST--
2+
Bug #79467 (data:// wrappers are writable)
3+
--FILE--
4+
<?php
5+
var_dump(file_put_contents('data://text/plain,cccc', 'data'));
6+
?>
7+
--EXPECTF--
8+
Notice: file_put_contents(): Stream is not writable in %s on line %d
9+
bool(false)

main/streams/memory.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -619,7 +619,7 @@ PHPAPI php_stream *_php_stream_temp_open(int mode, size_t max_memory_usage, char
619619
/* }}} */
620620

621621
PHPAPI const php_stream_ops php_stream_rfc2397_ops = {
622-
php_stream_temp_write, php_stream_temp_read,
622+
NULL, php_stream_temp_read,
623623
php_stream_temp_close, php_stream_temp_flush,
624624
"RFC2397",
625625
php_stream_temp_seek,

0 commit comments

Comments
 (0)