mirror of
https://github.com/php/php-src.git
synced 2025-08-16 05:58:45 +02:00
Merge branch 'PHP-8.1'
* PHP-8.1: Preserve file-position when php://temp switches to temporary file
This commit is contained in:
commit
30b2398860
2 changed files with 25 additions and 3 deletions
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)
|
|
@ -348,9 +348,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.");
|
||||
|
@ -360,6 +361,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…
Add table
Add a link
Reference in a new issue