Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion include/flatbuffers/idl.h
Original file line number Diff line number Diff line change
Expand Up @@ -245,9 +245,11 @@ class SymbolTable {
}

bool Add(const std::string& name, T* e) {
vec.emplace_back(e);
// Check for duplicate before adding to vec to avoid use-after-free:
// if caller deletes `e` on duplicate, the pointer must not remain in vec.
auto it = dict.find(name);
if (it != dict.end()) return true;
vec.emplace_back(e);
dict[name] = e;
return false;
}
Expand Down
11 changes: 8 additions & 3 deletions rust/flexbuffers/src/reader/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,12 @@ impl<B: Buffer> Reader<B> {
/// Otherwise Returns error.
pub fn get_bool(&self) -> Result<bool, Error> {
self.expect_type(FlexBufferType::Bool)?;
Ok(self.buffer[self.address..self.address + self.width.n_bytes()].iter().any(|&b| b != 0))
Ok(self
.buffer
.get(self.address..self.address + self.width.n_bytes())
.ok_or(Error::FlexbufferOutOfBounds)?
.iter()
.any(|&b| b != 0))
}

/// Gets the length of the key if this type is a key.
Expand Down Expand Up @@ -601,9 +606,9 @@ fn f64_from_le_bytes(bytes: [u8; 8]) -> f64 {
}

fn read_usize(buffer: &[u8], address: usize, width: BitWidth) -> usize {
let cursor = &buffer[address..];
let cursor = buffer.get(address..).unwrap_or_default();
match width {
BitWidth::W8 => cursor[0] as usize,
BitWidth::W8 => cursor.first().copied().unwrap_or_default() as usize,
BitWidth::W16 => cursor
.get(0..2)
.and_then(|s| s.try_into().ok())
Expand Down
Loading