Skip to content

Commit ee4683c

Browse files
committed
Merge branch 'PHP-7.3' into PHP-7.4
* PHP-7.3: Fix #74267: segfault with streams and invalid data
2 parents df2db7f + 12c59f6 commit ee4683c

File tree

3 files changed

+32
-4
lines changed

3 files changed

+32
-4
lines changed

NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ PHP NEWS
2323
(cmb)
2424
. Fixed several mostly Windows related phpdbg bugs. (cmb)
2525

26+
- Standard:
27+
. Fixed bug #74267 (segfault with streams and invalid data). (cmb)
28+
2629
11 Jun 2020, PHP 7.4.7
2730

2831
- Core:

ext/standard/filters.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -795,7 +795,7 @@ static php_conv_err_t php_conv_qprint_encode_convert(php_conv_qprint_encode *ins
795795
lb_ptr = inst->lb_ptr;
796796
lb_cnt = inst->lb_cnt;
797797

798-
if ((in_pp == NULL || in_left_p == NULL) && (lb_ptr >=lb_cnt)) {
798+
if (in_pp == NULL || in_left_p == NULL) {
799799
return PHP_CONV_ERR_SUCCESS;
800800
}
801801

@@ -1023,7 +1023,7 @@ static php_conv_err_t php_conv_qprint_decode_convert(php_conv_qprint_decode *ins
10231023
lb_ptr = inst->lb_ptr;
10241024
lb_cnt = inst->lb_cnt;
10251025

1026-
if ((in_pp == NULL || in_left_p == NULL) && lb_cnt == lb_ptr) {
1026+
if (in_pp == NULL || in_left_p == NULL) {
10271027
if (inst->scan_stat != 0) {
10281028
return PHP_CONV_ERR_UNEXPECTED_EOS;
10291029
}
@@ -1120,8 +1120,7 @@ static php_conv_err_t php_conv_qprint_decode_convert(php_conv_qprint_decode *ins
11201120
*ps == (unsigned char)inst->lbchars[lb_cnt]) {
11211121
lb_cnt++;
11221122
scan_stat = 5;
1123-
}
1124-
if (*ps != '\t' && *ps != ' ') {
1123+
} else if (*ps != '\t' && *ps != ' ') {
11251124
err = PHP_CONV_ERR_INVALID_SEQ;
11261125
goto out;
11271126
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
--TEST--
2+
Bug #74267 (segfault with streams and invalid data)
3+
--FILE--
4+
<?php
5+
$stream = fopen('php://memory', 'w');
6+
stream_filter_append($stream, 'convert.quoted-printable-decode', STREAM_FILTER_WRITE, ['line-break-chars' => "\r\n"]);
7+
8+
$lines = [
9+
"\r\n",
10+
" -=()\r\n",
11+
" -=\r\n",
12+
"\r\n"
13+
];
14+
15+
foreach ($lines as $line) {
16+
fwrite($stream, $line);
17+
}
18+
19+
fclose($stream);
20+
echo "done\n";
21+
?>
22+
--EXPECTF--
23+
Warning: fwrite(): stream filter (convert.quoted-printable-decode): invalid byte sequence in %s on line %d
24+
25+
Warning: fwrite(): stream filter (convert.quoted-printable-decode): invalid byte sequence in %s on line %d
26+
done

0 commit comments

Comments
 (0)