Skip to content

Fix convert.quoted-printable-encode losing or duplicating a partial line break - #24463

Open
sebxt wants to merge 1 commit into
php:PHP-8.4from
sebxt:fix/qp-encode-filter-partial-line-break
Open

sebxt wants to merge 1 commit into
php:PHP-8.4from
sebxt:fix/qp-encode-filter-partial-line-break

Conversation

@sebxt

@sebxt sebxt commented Oct 20, 2026

Copy link
Copy Markdown

When line-break-chars is set, php_conv_qprint_encode_convert() holds back characters that may start a line break sequence. If a write ended in the middle of such a sequence:

  • the converter started emitting the held back characters as encoded bytes but kept them counted in lb_cnt, so when the next write completed the sequence the line break was emitted again ("Hello=\r" followed by "\nWorld" decodes to "Hello=\r\r\nWorld");
  • if the output buffer was full at that point, the characters stayed pending, and the flush on close returned early without writing them ("a\r" encodes to "a").

This change keeps a partial line break pending at the end of the input until more data arrives, and emits it on the final flush (NULL input), which the converter previously ignored. The trailing whitespace lookahead is skipped when no input is left so it never reads from the NULL input pointer during the flush.

Output for input that does not end in a partial line break is unchanged. Added a test with single and split writes; every case now decodes back to the original data.

Fixes #24462

…ine break

Signed-off-by: Sebastian Turner <sebastiant3484@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant