Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: cobs accumulator out-of-bounds index when data is 1 byte too long #90

Merged

Conversation

jedrzejboczar
Copy link
Contributor

Currently there is an off-by-one error in bounds checking which may lead to panic! in self.extend_unchecked().

When calling:

let (take, release) = input.split_at(n + 1);

the take slice has length of n + 1 (slice::split_at), but currently the if condition checks for size n.

I added a test case that demonstrates the issue using CobsAccumulator<11> and feeding it with a 12-byte message. Without the fix this will panic:

thread 'accumulator::extend_unchecked_in_bounds_test' panicked at 'range end index 12 out of range for slice of length 11', library/core/src/slice/index.rs:73:5

@netlify
Copy link

netlify bot commented Feb 4, 2023

Deploy Preview for cute-starship-2d9c9b canceled.

Name Link
🔨 Latest commit f7d3812
🔍 Latest deploy log https://app.netlify.com/sites/cute-starship-2d9c9b/deploys/63dea682a4e9b6000947a918

@jamesmunns
Copy link
Owner

Thank you!

@jamesmunns jamesmunns merged commit 41c2ddb into jamesmunns:main Feb 16, 2023
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.

2 participants