Skip to content

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

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

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

Conversation

@iliaal

@iliaal iliaal commented Aug 21, 2026

Copy link
Copy Markdown
Owner

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.

@iliaal
iliaal force-pushed the fix/snprintf-negative-star-precision branch from fbed380 to 6df6249 Compare August 22, 2026 15:04
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.
@iliaal
iliaal force-pushed the fix/snprintf-negative-star-precision branch from 6df6249 to ca181af Compare August 22, 2026 15:45
@iliaal

iliaal commented Aug 22, 2026

Copy link
Copy Markdown
Owner Author

Upstream: php#23416

@iliaal iliaal closed this Aug 22, 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