Skip to content

ext/filter: encode 0xFF in FILTER_SANITIZE_ENCODED#22762

Open
iliaal wants to merge 1 commit into
php:PHP-8.4from
iliaal:fix/filter-sanitize-encoded-0xff
Open

ext/filter: encode 0xFF in FILTER_SANITIZE_ENCODED#22762
iliaal wants to merge 1 commit into
php:PHP-8.4from
iliaal:fix/filter-sanitize-encoded-0xff

Conversation

@iliaal

@iliaal iliaal commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

php_filter_encode_url() builds a 256-byte table marking which bytes need percent-encoding, but initializes it with memset(tmp, 1, sizeof(tmp) - 1), so tmp[255] is never written. Whether 0xFF gets encoded then depends on stack garbage.

On PHP-8.4 it currently reads as unencoded, which is visible from userland:

filter_var("\xFE\xFF\x00A", FILTER_SANITIZE_ENCODED);  // "%FE\xFF%00A", 0xFE encoded, 0xFF not

valgrind on the unpatched build:

Conditional jump or move depends on uninitialised value(s)
   at php_filter_encode_url (sanitizing_filters.c:83)
   by php_filter_encoded (sanitizing_filters.c:219)
 Uninitialised value was created by a stack allocation

Present on 8.3 through master, targeting 8.4 as the lowest actively supported branch.

php_filter_encode_url() initialized its 256-byte "must encode" table with
memset(tmp, 1, sizeof(tmp) - 1), leaving tmp[255] uninitialized. Whether
0xFF got percent-encoded then depended on stack garbage; valgrind reports
the read as a conditional jump on an uninitialised value. Initialize the
whole table.

Closes phpGH-22762
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