Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

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#3848
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

Conversation

@xenoninja

Copy link
Copy Markdown

When an offset-from-end line range used a very large value (for example, --line-range=:-18446744073709551614), print_file_ranges added one to the parsed usize and passed the result directly to VecDeque::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 VecDeque grow 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 - 1 and usize::MAX offsets.

Closes #3845.

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.

bat panics (capacity overflow) on a huge --line-range offset-from-end

1 participant

Morty Proxy This is a proxified and sanitized view of the page, visit original site.