Repository navigation
Bound pattern pad widths where they are parsed and used - #3688
Open
vera-rubin wants to merge 1 commit into
Open
vera-rubin wants to merge 1 commit into
vera-rubin wants to merge 1 commit into
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
handle_padspec_()builds the pad width from the pattern digits in asize_twith no limit, and caps it at 64 only at the end. A very long digit run can therefore wrap around first. For example,%-18446744073709551617npads to width 1 instead of the existing maximum of 64. The parser now stops accumulating once the width passesmax_width, so any oversized width ends up at 64.scoped_padder::pad_it()takes a view ofcountcharacters from its 64-characterspaces_buffer. It depends on the parser keeping the width within that size. It now clampscounttospaces_.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