Skip to content

Commit

Permalink
Fixed bug #69100
Browse files Browse the repository at this point in the history
  • Loading branch information
nikic committed Jul 17, 2019
1 parent bd05149 commit b864abf
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 9 deletions.
4 changes: 4 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ PHP NEWS
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
?? ??? 2019, PHP 7.2.22

- Standard:
. Fixed bug #69100 (Bus error from stream_copy_to_stream (file -> SSL stream)
with invalid length). (Nikita)

01 Aug 2019, PHP 7.2.21

- Fileinfo:
Expand Down
24 changes: 24 additions & 0 deletions ext/standard/tests/file/bug69100.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
--TEST--
Bug #69100: Bus error from stream_copy_to_stream (file -> SSL stream) with invalid length
--FILE--
<?php

$fileIn = __DIR__ . '/bug69100_in.txt';
$fileOut = __DIR__ . '/bug69100_out.txt';

file_put_contents($fileIn, str_repeat('A', 64 * 1024));
$fr = fopen($fileIn, 'rb');
$fw = fopen($fileOut, 'w');

var_dump(stream_copy_to_stream($fr, $fw, 32 * 1024));
var_dump(stream_copy_to_stream($fr, $fw, 64 * 1024));

fclose($fr);
fclose($fw);
unlink($fileIn);
unlink($fileOut);

?>
--EXPECT--
int(32768)
int(32768)
15 changes: 6 additions & 9 deletions main/streams/plain_wrapper.c
Original file line number Diff line number Diff line change
Expand Up @@ -696,18 +696,15 @@ static int php_stdiop_set_option(php_stream *stream, int option, int value, void
return fd == -1 ? PHP_STREAM_OPTION_RETURN_ERR : PHP_STREAM_OPTION_RETURN_OK;

case PHP_STREAM_MMAP_MAP_RANGE:
if(do_fstat(data, 1) != 0) {
if (do_fstat(data, 1) != 0) {
return PHP_STREAM_OPTION_RETURN_ERR;
}
if (range->length == 0 && range->offset > 0 && range->offset < data->sb.st_size) {
range->length = data->sb.st_size - range->offset;
}
if (range->length == 0 || range->length > data->sb.st_size) {
range->length = data->sb.st_size;
}
if (range->offset >= data->sb.st_size) {
if (range->offset > data->sb.st_size) {
range->offset = data->sb.st_size;
range->length = 0;
}
if (range->length == 0 ||
range->length > data->sb.st_size - range->offset) {
range->length = data->sb.st_size - range->offset;
}
switch (range->mode) {
case PHP_STREAM_MAP_MODE_READONLY:
Expand Down

0 comments on commit b864abf

Please sign in to comment.