Skip to content
Open
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
2 changes: 2 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ PHP NEWS
(Artem Ukrainskiy)
. Fixed array_udiff_assoc() and array_uintersect_assoc() clobbering the user
comparison callback. (lacatoire)
. Fixed bug GH-26041 (convert.quoted-printable-encode splits UTF-8
characters across lines in text mode). (Ilia Alshanetsky)

- Date:
. Fixed bug GH-26032 (DateTimeZone->getTransitions() includes too-early
Expand Down
10 changes: 9 additions & 1 deletion ext/standard/filters.c
Original file line number Diff line number Diff line change
Expand Up @@ -784,7 +784,15 @@ static php_conv_err_t php_conv_qprint_encode_convert(php_conv_qprint_encode *ins
line_ccnt--;
CONSUME_CHAR(ps, icnt, lb_ptr, lb_cnt);
} else {
if (line_ccnt < 4 && inst->lbchars != NULL) {
unsigned int encoded_len = 3;
if (!(opts & PHP_CONV_QPRINT_OPT_BINARY) && c >= 0xc2 && c <= 0xf4) {
unsigned int utf8_len = 2 + (c >= 0xe0) + (c >= 0xf0);
if (3 * utf8_len < inst->line_len) {
encoded_len = 3 * utf8_len;
}
}

if (line_ccnt <= encoded_len && inst->lbchars != NULL) {
if (ocnt < inst->lbchars_len + 1) {
err = PHP_CONV_ERR_TOO_BIG;
break;
Expand Down
47 changes: 47 additions & 0 deletions ext/standard/tests/filters/gh26041.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
--TEST--
GH-26041 (convert.quoted-printable-encode splits UTF-8 characters across lines)
--FILE--
<?php
function encode(string $input, int $width, bool $binary = false): void {
$options = ['line-length' => $width, 'line-break-chars' => "\r\n", 'binary' => $binary];

$read = fopen('php://memory', 'w+');
fwrite($read, $input);
rewind($read);
stream_filter_append($read, 'convert.quoted-printable-encode', STREAM_FILTER_READ, $options);
$encoded = stream_get_contents($read);
echo $encoded, "\n";

$write = fopen('php://memory', 'w+');
stream_filter_append($write, 'convert.quoted-printable-encode', STREAM_FILTER_WRITE, $options);
foreach (str_split($input) as $byte) {
fwrite($write, $byte);
}
rewind($write);
if (stream_get_contents($write) !== $encoded) {
echo "Write filter produced different output\n";
}
}

foreach ([[7, "\u{00A0}"], [4, "\u{20AC}"], [1, "\u{1F600}"]] as [$prefix, $char]) {
$exactFit = str_repeat('A', $prefix) . $char;
encode($exactFit . "\r\nA" . $exactFit, 14);
}
encode("A\u{1F600}", 7);
encode("AAAAAAAA\u{00A0}", 14, binary: true);
?>
--EXPECT--
AAAAAAA=C2=A0
AAAAAAAA=
=C2=A0
AAAA=E2=82=AC
AAAAA=
=E2=82=AC
A=F0=9F=98=80
AA=
=F0=9F=98=80
A=F0=
=9F=98=
=80
AAAAAAAA=C2=
=A0
Loading