Skip to content

zend_ast: Escape control bytes in exported string literals#98

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

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

Conversation

@iliaal

@iliaal iliaal commented Jun 16, 2026

Copy link
Copy Markdown
Owner

assert() failure messages were truncated at the first NUL byte when the asserted expression contained a string literal with a NUL, e.g. assert(!str_contains($string, "\x00")) produced only assert(!str_contains($string, '. The AST pretty-printer rendered string literals single-quoted with raw bytes; the NUL survived in the zend_string but assert() passes it to zend_throw_exception() as a const char*, which re-measures with strlen. Literals containing a control byte are now rendered double-quoted via zend_ast_export_qstr() so the byte is escaped as octal and no embedded NUL remains. Fixes php#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
@iliaal

iliaal commented Jun 16, 2026

Copy link
Copy Markdown
Owner Author

Promoted upstream to php#22350 (base PHP-8.4). Closing this fork PR; keeping the branch since the upstream PR's head points at it.

@iliaal iliaal closed this Jun 16, 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