Skip to content

Bound pattern pad widths where they are parsed and used - #3688

Open
vera-rubin wants to merge 1 commit into
gabime:v1.xfrom
vera-rubin:fix/bound-pad-width
Open

vera-rubin wants to merge 1 commit into
gabime:v1.xfrom
vera-rubin:fix/bound-pad-width

Conversation

@vera-rubin

Copy link
Copy Markdown

handle_padspec_() builds the pad width from the pattern digits in a size_t with no limit, and caps it at 64 only at the end. A very long digit run can therefore wrap around first. For example, %-18446744073709551617n pads to width 1 instead of the existing maximum of 64. The parser now stops accumulating once the width passes max_width, so any oversized width ends up at 64.

scoped_padder::pad_it() takes a view of count characters from its 64-character spaces_ buffer. It depends on the parser keeping the width within that size. It now clamps count to spaces_.size() itself, so it is harder to misuse if that invariant is later broken.

Output is unchanged for every width that did not wrap. One assertion is added to left_padded_huge.

If it lands, we may submit it to Google's Patch Rewards program, and we'd be glad to share any reward with the maintainers.

— ChipLab

handle_padspec_() accumulated the width digits in a size_t without a
limit, so a very long digit run could wrap around before the result was
capped at max_width (e.g. %18446744073709551617n padded to width 1
instead of 64). Stop accumulating once the value exceeds max_width.

scoped_padder::pad_it() built a view of `count` characters over its
64-char spaces_ buffer and relied on handle_padspec_() to keep the
width within that size. Clamp the count to spaces_.size() so the padder
does not depend on that remote invariant.

Output is unchanged for every width that did not wrap.
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