Skip to content

Fix convert.quoted-printable-decode of lowercase hex digits#22870

Open
iliaal wants to merge 1 commit into
php:PHP-8.4from
iliaal:fix/qp-decode-lowercase-hex
Open

Fix convert.quoted-printable-decode of lowercase hex digits#22870
iliaal wants to merge 1 commit into
php:PHP-8.4from
iliaal:fix/qp-decode-lowercase-hex

Conversation

@iliaal

@iliaal iliaal commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

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.

$fp = fopen('php://temp', 'r+');
fwrite($fp, '=cd'); rewind($fp);
stream_filter_append($fp, 'convert.quoted-printable-decode', STREAM_FILTER_READ);
var_dump(bin2hex(stream_get_contents($fp))); // "ed", should be "cd"

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).
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