Skip to content

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

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

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

Conversation

@iliaal

@iliaal iliaal commented Jul 23, 2026

Copy link
Copy Markdown
Owner

The convert.quoted-printable-decode stream filter accepts lowercase hex digits (isxdigit() passes a-f) but its nibble math, *ps >= 'A' ? *ps - 0x37 : *ps - 0x30, only handles uppercase, so a hex escape with a lowercase digit decodes to the wrong byte. quoted_printable_decode() handles 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).
@iliaal

iliaal commented Jul 23, 2026

Copy link
Copy Markdown
Owner Author

Promoted upstream: php#22870

@iliaal iliaal closed this Jul 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant