Fix convert.quoted-printable-decode of lowercase hex digits#22870
Fix convert.quoted-printable-decode of lowercase hex digits#22870iliaal wants to merge 1 commit into
Conversation
6b3aa52 to
0db9b02
Compare
The stream filter's nibble decoder accepts lowercase a-f via isxdigit() but decodes them as (*ps - 0x37), correct only for uppercase A-F. Bytes whose hex spelling uses a lowercase digit are silently corrupted (=cd decodes to 0xed, =0a to 0x2a). Decode lowercase with (*ps - 0x57).
0db9b02 to
f28afa8
Compare
|
The filter documentation refers to
Since decoding lowercase digits has never worked properly, and since fixing invalid inputs often lead to bugs or security issues, I would be in favor of changing Edit: I see now that only the filter doesn't decode lowercase hex letter properly. In that case I would suggestion to only change the filter, and to propose a deprecation of this behavior for the function (unless https://github.com/php/policies/pull/27/changes applies, but I'm not sure. cc @Girgias @TimWolla) |
|
The RFC also says: "An "=" followed by two hexadecimal digits, one or both of which are lowercase letters in "abcdef", is formally illegal. A robust implementation might choose to recognize them as the corresponding uppercase letters." base64_decode() has a $strict argument, maybe that's the direction. |
|
On the strict direction: I'd keep that off this fix. It's an 8.4 bug fix, and the filter today doesn't reject lowercase, it silently decodes it to the wrong byte ( The strict form (deprecate the leniency in both, or a |
The convert.quoted-printable-decode stream filter accepts lowercase hex digits (isxdigit() passes a-f) but its nibble math only handles uppercase, so a hex escape with a lowercase digit decodes to the wrong byte. quoted_printable_decode() decodes lowercase correctly, so the filter and the function disagree.