mirror of
https://github.com/php/php-src.git
synced 2025-08-16 05:58:45 +02:00
MFH: Fixed bug #48309 (stream_copy_to_stream() and fpasstru() do not
update stream position of plain files)
This commit is contained in:
parent
7c30401aec
commit
c79528a26d
4 changed files with 55 additions and 3 deletions
33
ext/standard/tests/streams/bug48309.phpt
Normal file
33
ext/standard/tests/streams/bug48309.phpt
Normal file
|
@ -0,0 +1,33 @@
|
|||
--TEST--
|
||||
Bug #48309 (stream_copy_to_stream() and fpasstru() do not update stream position)
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
$tmp = tmpfile();
|
||||
fwrite($tmp, b'test');
|
||||
fseek($tmp, 0, SEEK_SET);
|
||||
|
||||
echo "-- stream_copy_to_stream() --\n";
|
||||
|
||||
fseek($tmp, 0, SEEK_SET);
|
||||
stream_copy_to_stream($tmp, STDOUT, 2);
|
||||
|
||||
echo "\n";
|
||||
var_dump(stream_get_contents($tmp));
|
||||
|
||||
echo "-- fpassthru() --\n";
|
||||
|
||||
fseek($tmp, 0, SEEK_SET);
|
||||
fpassthru($tmp);
|
||||
|
||||
echo "\n";
|
||||
var_dump(stream_get_contents($tmp));
|
||||
|
||||
?>
|
||||
--EXPECTF--
|
||||
-- stream_copy_to_stream() --
|
||||
te
|
||||
string(2) "st"
|
||||
-- fpassthru() --
|
||||
test
|
||||
string(0) ""
|
|
@ -51,6 +51,20 @@ PHPAPI int _php_stream_mmap_unmap(php_stream *stream TSRMLS_DC)
|
|||
return php_stream_set_option(stream, PHP_STREAM_OPTION_MMAP_API, PHP_STREAM_MMAP_UNMAP, NULL) == PHP_STREAM_OPTION_RETURN_OK ? 1 : 0;
|
||||
}
|
||||
|
||||
PHPAPI int _php_stream_mmap_unmap_ex(php_stream *stream, off_t readden TSRMLS_DC)
|
||||
{
|
||||
int ret = 1;
|
||||
|
||||
if (php_stream_seek(stream, readden, SEEK_CUR) != 0) {
|
||||
ret = 0;
|
||||
}
|
||||
if (php_stream_mmap_unmap(stream) == 0) {
|
||||
ret = 0;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
* Local variables:
|
||||
* tab-width: 4
|
||||
|
|
|
@ -58,6 +58,8 @@ typedef struct {
|
|||
|
||||
} php_stream_mmap_range;
|
||||
|
||||
#define PHP_STREAM_MMAP_ALL 0
|
||||
|
||||
#define php_stream_mmap_supported(stream) (_php_stream_set_option((stream), PHP_STREAM_OPTION_MMAP_API, PHP_STREAM_MMAP_SUPPORTED, NULL TSRMLS_CC) == 0 ? 1 : 0)
|
||||
|
||||
/* Returns 1 if the stream in its current state can be memory mapped,
|
||||
|
@ -71,6 +73,9 @@ PHPAPI char *_php_stream_mmap_range(php_stream *stream, size_t offset, size_t le
|
|||
/* un-maps the last mapped range */
|
||||
PHPAPI int _php_stream_mmap_unmap(php_stream *stream TSRMLS_DC);
|
||||
#define php_stream_mmap_unmap(stream) _php_stream_mmap_unmap((stream) TSRMLS_CC)
|
||||
|
||||
PHPAPI int _php_stream_mmap_unmap_ex(php_stream *stream, off_t readden TSRMLS_DC);
|
||||
#define php_stream_mmap_unmap_ex(stream, readden) _php_stream_mmap_unmap_ex((stream), (readden) TSRMLS_CC)
|
||||
END_EXTERN_C()
|
||||
|
||||
/*
|
||||
|
|
|
@ -1215,12 +1215,12 @@ PHPAPI size_t _php_stream_passthru(php_stream * stream STREAMS_DC TSRMLS_DC)
|
|||
char *p;
|
||||
size_t mapped;
|
||||
|
||||
p = php_stream_mmap_range(stream, php_stream_tell(stream), PHP_STREAM_COPY_ALL, PHP_STREAM_MAP_MODE_SHARED_READONLY, &mapped);
|
||||
p = php_stream_mmap_range(stream, php_stream_tell(stream), PHP_STREAM_MMAP_ALL, PHP_STREAM_MAP_MODE_SHARED_READONLY, &mapped);
|
||||
|
||||
if (p) {
|
||||
PHPWRITE(p, mapped);
|
||||
|
||||
php_stream_mmap_unmap(stream);
|
||||
php_stream_mmap_unmap_ex(stream, mapped);
|
||||
|
||||
return mapped;
|
||||
}
|
||||
|
@ -1340,7 +1340,7 @@ PHPAPI size_t _php_stream_copy_to_stream_ex(php_stream *src, php_stream *dest, s
|
|||
if (p) {
|
||||
mapped = php_stream_write(dest, p, mapped);
|
||||
|
||||
php_stream_mmap_unmap(src);
|
||||
php_stream_mmap_unmap_ex(src, mapped);
|
||||
|
||||
*len = mapped;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue