Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions ext/standard/filters.c
Original file line number Diff line number Diff line change
Expand Up @@ -788,7 +788,7 @@ static php_conv_err_t php_conv_qprint_encode_convert(php_conv_qprint_encode *ins
lb_ptr = inst->lb_ptr;
lb_cnt = inst->lb_cnt;

if ((in_pp == NULL || in_left_p == NULL) && (lb_ptr >=lb_cnt)) {
if (in_pp == NULL || in_left_p == NULL) {
return PHP_CONV_ERR_SUCCESS;
}

Expand Down Expand Up @@ -1016,7 +1016,7 @@ static php_conv_err_t php_conv_qprint_decode_convert(php_conv_qprint_decode *ins
lb_ptr = inst->lb_ptr;
lb_cnt = inst->lb_cnt;

if ((in_pp == NULL || in_left_p == NULL) && lb_cnt == lb_ptr) {
if (in_pp == NULL || in_left_p == NULL) {
if (inst->scan_stat != 0) {
return PHP_CONV_ERR_UNEXPECTED_EOS;
}
Expand Down Expand Up @@ -1113,8 +1113,7 @@ static php_conv_err_t php_conv_qprint_decode_convert(php_conv_qprint_decode *ins
*ps == (unsigned char)inst->lbchars[lb_cnt]) {
lb_cnt++;
scan_stat = 5;
}
if (*ps != '\t' && *ps != ' ') {
} else if (*ps != '\t' && *ps != ' ') {
err = PHP_CONV_ERR_INVALID_SEQ;
goto out;
}
Expand Down
26 changes: 26 additions & 0 deletions ext/standard/tests/filters/bug74267.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
--TEST--
Bug #74267 (segfault with streams and invalid data)
--FILE--
<?php
$stream = fopen('php://memory', 'w');
stream_filter_append($stream, 'convert.quoted-printable-decode', STREAM_FILTER_WRITE, ['line-break-chars' => "\r\n"]);

$lines = [
"\r\n",
" -=()\r\n",
" -=\r\n",
"\r\n"
];

foreach ($lines as $line) {
fwrite($stream, $line);
}

fclose($stream);
echo "done\n";
?>
--EXPECTF--
Warning: fwrite(): stream filter (convert.quoted-printable-decode): invalid byte sequence in %s on line %d

Warning: fwrite(): stream filter (convert.quoted-printable-decode): invalid byte sequence in %s on line %d
done