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

Merged
merged 2 commits into from
Oct 22, 2024

Conversation

beholdnec
Copy link
Contributor

@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.

@beholdnec beholdnec force-pushed the buffer-slice-bounds-check branch from 0dc91ab to 58b25a4 Compare October 21, 2024 22:05
Copy link
Member

@Wumpf Wumpf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

very nicely done! Thank you so much!

wgpu/src/api/buffer.rs Outdated Show resolved Hide resolved
@Wumpf Wumpf linked an issue Oct 22, 2024 that may be closed by this pull request
@Wumpf Wumpf merged commit e711a35 into gfx-rs:trunk Oct 22, 2024
27 checks passed
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.

Buffer slice method should panic when index is out of range (?)
2 participants