From ee6db3d78c23c3d453be4c38f0e450a457d71c7d Mon Sep 17 00:00:00 2001 From: Sebastian Turner Date: Mon, 19 Oct 2026 08:32:51 -0700 Subject: [PATCH] Fix quoted_printable_encode() exceeding the line length for bytes 0xF5 to 0xFF Signed-off-by: Sebastian Turner --- ext/standard/quot_print.c | 2 +- .../quoted_printable_encode_line_length.phpt | 20 +++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 ext/standard/tests/strings/quoted_printable_encode_line_length.phpt diff --git a/ext/standard/quot_print.c b/ext/standard/quot_print.c index 75606c44a980..0fc8c27343c9 100644 --- a/ext/standard/quot_print.c +++ b/ext/standard/quot_print.c @@ -155,7 +155,7 @@ PHPAPI zend_string *php_quot_print_encode(const unsigned char *str, size_t lengt lp = 0; } else { if (iscntrl (c) || (c == 0x7f) || (c & 0x80) || (c == '=') || ((c == ' ') && (*str == '\015'))) { - if ((((lp+= 3) > PHP_QPRINT_MAXL) && (c <= 0x7f)) + if ((((lp+= 3) > PHP_QPRINT_MAXL) && ((c <= 0x7f) || (c > 0xf4))) || ((c > 0x7f) && (c <= 0xdf) && ((lp + 3) > PHP_QPRINT_MAXL)) || ((c > 0xdf) && (c <= 0xef) && ((lp + 6) > PHP_QPRINT_MAXL)) || ((c > 0xef) && (c <= 0xf4) && ((lp + 9) > PHP_QPRINT_MAXL))) { diff --git a/ext/standard/tests/strings/quoted_printable_encode_line_length.phpt b/ext/standard/tests/strings/quoted_printable_encode_line_length.phpt new file mode 100644 index 000000000000..b7cd09b52a64 --- /dev/null +++ b/ext/standard/tests/strings/quoted_printable_encode_line_length.phpt @@ -0,0 +1,20 @@ +--TEST-- +quoted_printable_encode() keeps lines within 76 characters for bytes 0xF5 to 0xFF +--FILE-- + +--EXPECT-- +f5: 76,15 +bool(true) +f8: 76,15 +bool(true) +ff: 76,15 +bool(true)