mirror of
https://github.com/php/php-src.git
synced 2024-11-24 02:15:04 +08:00
Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0: Preserve file-position when php://temp switches to temporary file
This commit is contained in:
commit
e3a5e424f6
4
NEWS
4
NEWS
@ -21,6 +21,10 @@ PHP NEWS
|
||||
. Fixed bug GH-8267 (MySQLi uses unsupported format specifier on Windows).
|
||||
(cmb)
|
||||
|
||||
- Streams:
|
||||
. Fixed php://temp does not preserve file-position when switched to temporary
|
||||
file. (Bernd Holzmüller)
|
||||
|
||||
14 Apr 2022, PHP 8.1.5
|
||||
|
||||
- Core:
|
||||
|
20
ext/standard/tests/streams/temp_stream_seek.phpt
Normal file
20
ext/standard/tests/streams/temp_stream_seek.phpt
Normal file
@ -0,0 +1,20 @@
|
||||
--TEST--
|
||||
BUG: php://temp does not preserve file-pointer once it switches from memory to temporary file
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
$f = fopen('php://temp/maxmemory:1024', 'r+');
|
||||
fwrite($f, str_repeat("1", 738));
|
||||
fseek($f, 0, SEEK_SET);
|
||||
fwrite($f, str_repeat("2", 512));
|
||||
|
||||
fseek($f, 0, SEEK_SET);
|
||||
var_dump(fread($f, 16));
|
||||
|
||||
fseek($f, 0, SEEK_END);
|
||||
var_dump(ftell($f));
|
||||
|
||||
?>
|
||||
--EXPECT--
|
||||
string(16) "2222222222222222"
|
||||
int(738)
|
@ -346,9 +346,10 @@ static ssize_t php_stream_temp_write(php_stream *stream, const char *buf, size_t
|
||||
return -1;
|
||||
}
|
||||
if (php_stream_is(ts->innerstream, PHP_STREAM_IS_MEMORY)) {
|
||||
zend_string *membuf = php_stream_memory_get_buffer(ts->innerstream);
|
||||
|
||||
if (ZSTR_LEN(membuf) + count >= ts->smax) {
|
||||
zend_off_t pos = php_stream_tell(ts->innerstream);
|
||||
|
||||
if (pos + count >= ts->smax) {
|
||||
zend_string *membuf = php_stream_memory_get_buffer(ts->innerstream);
|
||||
php_stream *file = php_stream_fopen_temporary_file(ts->tmpdir, "php", NULL);
|
||||
if (file == NULL) {
|
||||
php_error_docref(NULL, E_WARNING, "Unable to create temporary file, Check permissions in temporary files directory.");
|
||||
@ -358,6 +359,7 @@ static ssize_t php_stream_temp_write(php_stream *stream, const char *buf, size_t
|
||||
php_stream_free_enclosed(ts->innerstream, PHP_STREAM_FREE_CLOSE);
|
||||
ts->innerstream = file;
|
||||
php_stream_encloses(stream, ts->innerstream);
|
||||
php_stream_seek(ts->innerstream, pos, SEEK_SET);
|
||||
}
|
||||
}
|
||||
return php_stream_write(ts->innerstream, buf, count);
|
||||
|
Loading…
Reference in New Issue
Block a user