Fix huge --line-range offset-from-end panic#3848
Open
xenoninja wants to merge 2 commits into
sharkdp:mastersharkdp/bat:masterfrom
xenoninja:fix/capacity-overflow-on-huge-offsetxenoninja/bat:fix/capacity-overflow-on-huge-offsetCopy head branch name to clipboard
Open
Fix huge --line-range offset-from-end panic#3848xenoninja wants to merge 2 commits intosharkdp:mastersharkdp/bat:masterfrom xenoninja:fix/capacity-overflow-on-huge-offsetxenoninja/bat:fix/capacity-overflow-on-huge-offsetCopy head branch name to clipboard
--line-range offset-from-end panic#3848xenoninja wants to merge 2 commits into
sharkdp:mastersharkdp/bat:masterfrom
xenoninja:fix/capacity-overflow-on-huge-offsetxenoninja/bat:fix/capacity-overflow-on-huge-offsetCopy head branch name to clipboard
Conversation
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.
When an offset-from-end line range used a very large value (for example,
--line-range=:-18446744073709551614),print_file_rangesadded one to the parsedusizeand passed the result directly toVecDeque::with_capacity. This either triggered a capacity overflow while allocating or overflowed the addition itself.Use saturating arithmetic for the look-ahead buffer size and let the
VecDequegrow with the input instead of reserving the user-provided offset up front. This preserves existing range behavior while making memory usage depend on the actual input; offsets beyond the input now produce an empty range instead of panicking.Add an integration test covering both
usize::MAX - 1andusize::MAXoffsets.Closes #3845.