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

Add bounds check to Buffer slice method #6432

Open
wants to merge 1 commit into
base: trunk
Choose a base branch
from

Conversation

beholdnec
Copy link

@beholdnec beholdnec commented Oct 21, 2024

Connections
#6428

Description
The Buffer slice method currently doesn't perform bounds checks on the offset and size arguments. This is inconsistent with Rust's Array and Vec, which panic when attempting to take a slice out of bounds.

I recently encountered a confusing issue caused by attempting to map a buffer out of bounds. Making the Buffer slice method consistent with Rust's standard libraries by panicking in such cases would help debug such issues.

Testing
This PR includes test cases for the bounds-checking function, including tests for integer wraparound.

Checklist

  • Run cargo fmt.
  • Run taplo format.
  • Run cargo clippy. If applicable, add:
    • --target wasm32-unknown-unknown
    • --target wasm32-unknown-emscripten
  • Run cargo xtask test to run tests.
  • Add change to CHANGELOG.md. See simple instructions inside file.

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