You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(Net): keep =? and delimiters when text is not an encoded word #5564 - #5596
add parseEncodedWord in Net/src/MessageHeader.cpp to validate RFC 2047 encoded-word structure (=?charset?encoding?encoded-text?=) and check that encoding is B or Q.
in MessageHeader::decodeWord, retain =? when text is not a complete valid encoded word.
per RFC 2047 section 6.2, only ignore linear-white-space between adjacent words when both are valid and decode successfully; keep linear-white-space if either word is displayed verbatim.
in decodeRFC2047, return malformed Base64 and invalid Q-encoding sequences verbatim with original delimiters instead of silently corrupting or deleting values.
add unit tests in Net/testsuite/src/MessageHeaderTest.cpp covering incomplete words (=?base64?...?=), non-encoded =? in query strings (https://example.com/?a=?b), unknown encodings (=?x?y?z?=), malformed Base64/Q-encoding sequences, adjacent word whitespace handling, delimiter preservation in decodeRFC2047, and header deserialization with MessageHeader::read.
why
MessageHeader::decodeWord stripped =? as soon as it matched, but if the following text was not a complete encoded word (missing delimiters, malformed tokens, or ordinary text like URL query parameters), the stripped =? was dropped from the output. Additionally, decodeRFC2047 dropped delimiters on unrecognized encodings (such as neither B nor Q), violating RFC 2047 section 6.1 which requires unencoded or unrecognized words to be emitted verbatim. Furthermore, whitespace between adjacent words was collapsed even when one of the words was displayed verbatim, and decoding errors in Base64 or Q-encoding produced empty/corrupted strings instead of verbatim words.
checks
built Net-testrunner with GCC 13.3 on Linux.
MessageHeaderTest passes (all 31 test cases pass).
MessagesTestSuite passes (all 50 test cases pass).
HTTPTestSuite passes (all 80 test cases pass).
HTTPClientTestSuite passes (all 81 test cases pass).
HTTPServerTestSuite passes (all 35 test cases pass).
This PR addresses #5564 by preserving non-encoded and malformed header text during POCO’s RFC 2047 decoding, including automatic decoding in MessageHeader::read().
Changes:
Adds encoded-word parsing and preserves delimiters when decoding fails.
Limits whitespace removal to successfully decoded adjacent words.
Adds regression tests for malformed inputs, delimiter preservation and header deserialization.
File
Description
Net/testsuite/src/MessageHeaderTest.cpp
Adds decoding and header-reading regression cases.
Net/src/MessageHeader.cpp
Adds validation and verbatim fallback; revises adjacent-word whitespace handling.
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
Repeated malformed encoded-word prefixes cause quadratic scanning during automatic header decoding.
No open issues 🎉
1 previously missed issue
In code that hasn't changed since last review
Avoid quadratic scans for incomplete encoded-word prefixes
Net/src/MessageHeader.cpp:136
Repeated incomplete prefixes such as =?UTF-8?Q?abc make this search scan the remaining suffix for every retry in decodeWord(), causing quadratic work in automatically decoded header values. Search for the next ? and reject the candidate unless it is followed by =; encoded-text cannot contain ?, so scanning beyond it is unnecessary.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
fixes #5564
what changed
why
MessageHeader::decodeWord stripped =? as soon as it matched, but if the following text was not a complete encoded word (missing delimiters, malformed tokens, or ordinary text like URL query parameters), the stripped =? was dropped from the output. Additionally, decodeRFC2047 dropped delimiters on unrecognized encodings (such as neither B nor Q), violating RFC 2047 section 6.1 which requires unencoded or unrecognized words to be emitted verbatim. Furthermore, whitespace between adjacent words was collapsed even when one of the words was displayed verbatim, and decoding errors in Base64 or Q-encoding produced empty/corrupted strings instead of verbatim words.
checks