Skip to content

Fix unbounded write on negative star precision in format_converter - #23416

Open
iliaal wants to merge 1 commit into
php:PHP-8.4from
iliaal:fix/snprintf-negative-star-precision
Open

Fix unbounded write on negative star precision in format_converter#23416
iliaal wants to merge 1 commit into
php:PHP-8.4from
iliaal:fix/snprintf-negative-star-precision

Conversation

@iliaal

@iliaal iliaal commented Aug 22, 2026

Copy link
Copy Markdown
Contributor

A negative star precision was only clamped to -1, so FIX_PRECISION() treated it as SIZE_MAX and wrote backwards through the buffer. Treat omitted precision that way in format_converter() only. xbuf_format_converter() keeps -1 as the %H shortest-float sentinel used by serialize_precision.

A "%.*[diouxX]" conversion with a negative precision was only clamped
to -1, which FIX_PRECISION() compares against a size_t: (size_t)-1
turns the zero-padding loop into an unbounded backward write through
num_buf and the stack. Treat a negative star precision as omitted in
format_converter() only; xbuf_format_converter() keeps -1 as the %H
shortest-float sentinel used by serialize_precision.
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