Skip to content

Commit 79efd55

Browse files
committed
Merge branch 'PHP-7.2' into PHP-7.3
2 parents e7e66d5 + b864abf commit 79efd55

File tree

3 files changed

+34
-9
lines changed

3 files changed

+34
-9
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ PHP NEWS
22
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
33
?? ??? ????, PHP 7.3.9
44

5+
- Standard:
6+
. Fixed bug #69100 (Bus error from stream_copy_to_stream (file -> SSL stream)
7+
with invalid length). (Nikita)
8+
59
01 Aug 2019, PHP 7.3.8
610

711
- Core:

ext/standard/tests/file/bug69100.phpt

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
--TEST--
2+
Bug #69100: Bus error from stream_copy_to_stream (file -> SSL stream) with invalid length
3+
--FILE--
4+
<?php
5+
6+
$fileIn = __DIR__ . '/bug69100_in.txt';
7+
$fileOut = __DIR__ . '/bug69100_out.txt';
8+
9+
file_put_contents($fileIn, str_repeat('A', 64 * 1024));
10+
$fr = fopen($fileIn, 'rb');
11+
$fw = fopen($fileOut, 'w');
12+
13+
var_dump(stream_copy_to_stream($fr, $fw, 32 * 1024));
14+
var_dump(stream_copy_to_stream($fr, $fw, 64 * 1024));
15+
16+
fclose($fr);
17+
fclose($fw);
18+
unlink($fileIn);
19+
unlink($fileOut);
20+
21+
?>
22+
--EXPECT--
23+
int(32768)
24+
int(32768)

main/streams/plain_wrapper.c

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -694,18 +694,15 @@ static int php_stdiop_set_option(php_stream *stream, int option, int value, void
694694
return fd == -1 ? PHP_STREAM_OPTION_RETURN_ERR : PHP_STREAM_OPTION_RETURN_OK;
695695

696696
case PHP_STREAM_MMAP_MAP_RANGE:
697-
if(do_fstat(data, 1) != 0) {
697+
if (do_fstat(data, 1) != 0) {
698698
return PHP_STREAM_OPTION_RETURN_ERR;
699699
}
700-
if (range->length == 0 && range->offset > 0 && range->offset < data->sb.st_size) {
701-
range->length = data->sb.st_size - range->offset;
702-
}
703-
if (range->length == 0 || range->length > data->sb.st_size) {
704-
range->length = data->sb.st_size;
705-
}
706-
if (range->offset >= data->sb.st_size) {
700+
if (range->offset > data->sb.st_size) {
707701
range->offset = data->sb.st_size;
708-
range->length = 0;
702+
}
703+
if (range->length == 0 ||
704+
range->length > data->sb.st_size - range->offset) {
705+
range->length = data->sb.st_size - range->offset;
709706
}
710707
switch (range->mode) {
711708
case PHP_STREAM_MAP_MODE_READONLY:

0 commit comments

Comments
 (0)