mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-02 04:04:19 +00:00
[Rust] Add length checks to arrays and vectors. (#7130)
* [Rust] Add length checks to arrays and vectors. The previous behavior allowed for out of bounds access in the public API (#7011). * bump semver and test warning Co-authored-by: Casper Neo <cneo@google.com>
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "flatbuffers"
|
||||
version = "2.1.0"
|
||||
version = "2.1.1"
|
||||
edition = "2018"
|
||||
authors = ["Robert Winslow <hello@rwinslow.com>", "FlatBuffers Maintainers"]
|
||||
license = "Apache-2.0"
|
||||
|
||||
@@ -39,7 +39,7 @@ where
|
||||
impl<'a, T: 'a, const N: usize> Array<'a, T, N> {
|
||||
#[inline(always)]
|
||||
pub fn new(buf: &'a [u8]) -> Self {
|
||||
debug_assert!(size_of::<T>() * N == buf.len());
|
||||
assert!(size_of::<T>() * N == buf.len());
|
||||
|
||||
Array {
|
||||
0: buf,
|
||||
@@ -59,7 +59,7 @@ impl<'a, T: 'a, const N: usize> Array<'a, T, N> {
|
||||
impl<'a, T: Follow<'a> + 'a, const N: usize> Array<'a, T, N> {
|
||||
#[inline(always)]
|
||||
pub fn get(&self, idx: usize) -> T::Inner {
|
||||
debug_assert!(idx < N);
|
||||
assert!(idx < N);
|
||||
let sz = size_of::<T>();
|
||||
T::follow(self.0, sz * idx)
|
||||
}
|
||||
|
||||
@@ -84,7 +84,7 @@ impl<'a, T: 'a> Vector<'a, T> {
|
||||
impl<'a, T: Follow<'a> + 'a> Vector<'a, T> {
|
||||
#[inline(always)]
|
||||
pub fn get(&self, idx: usize) -> T::Inner {
|
||||
debug_assert!(idx < self.len() as usize);
|
||||
assert!(idx < self.len() as usize);
|
||||
let sz = size_of::<T>();
|
||||
debug_assert!(sz > 0);
|
||||
T::follow(self.0, self.1 as usize + SIZE_UOFFSET + sz * idx)
|
||||
|
||||
Reference in New Issue
Block a user