Skip to content

zend_ast: Escape control bytes in exported string literals#22350

Open
iliaal wants to merge 1 commit into
php:PHP-8.4from
iliaal:fix/gh-22290-ast-export-nul
Open

zend_ast: Escape control bytes in exported string literals#22350
iliaal wants to merge 1 commit into
php:PHP-8.4from
iliaal:fix/gh-22290-ast-export-nul

Conversation

@iliaal

@iliaal iliaal commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

The AST pretty-printer rendered string literals single-quoted with raw bytes. A literal containing a NUL kept the byte in the resulting zend_string, but assert() passes that string to zend_throw_exception() as a const char*, so the failure message was truncated at the first NUL (the rest of the expression was lost).

Render literals that contain a control byte double-quoted via zend_ast_export_qstr(), which escapes those bytes as octal, so no embedded NUL survives and the message is complete. Strings without control bytes are unchanged.

Fixes GH-22290

The AST pretty-printer rendered string literals in single quotes,
appending each byte verbatim. A literal containing a NUL kept the byte
in the resulting string, but assert() hands that string to
zend_throw_exception() as a const char*, so the failure message was
truncated at the first NUL (the closing of the expression was lost).

Render literals that contain a control byte double-quoted via
zend_ast_export_qstr(), which escapes those bytes as octal. The embedded
NUL no longer survives, so the message is complete, and the byte is shown
in escaped form. Strings without control bytes are unchanged.

Fixes phpGH-22290
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.

assert() failure errors do not correctly handle ASTs with strings containing NUL

1 participant