Skip to content

Commit b864abf

Browse files
committed
Fixed bug #69100
1 parent bd05149 commit b864abf

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
?? ??? 2019, PHP 7.2.22
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.2.21
610

711
- Fileinfo:

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
@@ -696,18 +696,15 @@ static int php_stdiop_set_option(php_stream *stream, int option, int value, void
696696
return fd == -1 ? PHP_STREAM_OPTION_RETURN_ERR : PHP_STREAM_OPTION_RETURN_OK;
697697

698698
case PHP_STREAM_MMAP_MAP_RANGE:
699-
if(do_fstat(data, 1) != 0) {
699+
if (do_fstat(data, 1) != 0) {
700700
return PHP_STREAM_OPTION_RETURN_ERR;
701701
}
702-
if (range->length == 0 && range->offset > 0 && range->offset < data->sb.st_size) {
703-
range->length = data->sb.st_size - range->offset;
704-
}
705-
if (range->length == 0 || range->length > data->sb.st_size) {
706-
range->length = data->sb.st_size;
707-
}
708-
if (range->offset >= data->sb.st_size) {
702+
if (range->offset > data->sb.st_size) {
709703
range->offset = data->sb.st_size;
710-
range->length = 0;
704+
}
705+
if (range->length == 0 ||
706+
range->length > data->sb.st_size - range->offset) {
707+
range->length = data->sb.st_size - range->offset;
711708
}
712709
switch (range->mode) {
713710
case PHP_STREAM_MAP_MODE_READONLY:

0 commit comments

Comments
 (0)