Skip to content
Merged
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
10 changes: 7 additions & 3 deletions rust/flatbuffers/src/verifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ fn trace_elem<T>(res: Result<T>, index: usize, position: usize) -> Result<T> {
}

#[derive(Debug, Clone, PartialEq, Eq)]
pub struct VerifierOptions {
pub struct VerifierOptions<'a> {
/// Maximum depth of nested tables allowed in a valid flatbuffer.
pub max_depth: usize,
/// Maximum number of tables allowed in a valid flatbuffer.
Expand All @@ -289,16 +289,20 @@ pub struct VerifierOptions {
// probably want an option to ignore utf8 errors since strings come from c++
// options to error un-recognized enums and unions? possible footgun.
// Ignore nested flatbuffers, etc?

/// The name of the table to use as the root table instead of the schema root.
pub root_table_name: Option<&'a str>,
}

impl Default for VerifierOptions {
impl Default for VerifierOptions<'_> {
fn default() -> Self {
Self {
max_depth: 64,
max_tables: 1_000_000,
// size_ might do something different.
max_apparent_size: 1 << 31,
ignore_missing_null_terminator: false,
root_table_name: None,
}
}
}
Expand All @@ -307,7 +311,7 @@ impl Default for VerifierOptions {
#[derive(Debug)]
pub struct Verifier<'opts, 'buf> {
buffer: &'buf [u8],
opts: &'opts VerifierOptions,
opts: &'opts VerifierOptions<'opts>,
depth: usize,
num_tables: usize,
apparent_size: usize,
Expand Down
10 changes: 8 additions & 2 deletions rust/reflection/src/reflection_verifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,14 @@ pub fn verify_with_options(
buf_loc_to_obj_idx: &mut HashMap<usize, i32>,
) -> FlatbufferResult<()> {
let mut verifier = Verifier::new(opts, buffer);
if let Some(table_object) = schema.root_table() {
if let core::result::Result::Ok(table_pos) = verifier.get_uoffset(0) {
let root_table = match opts.root_table_name {
Some(root_table_name) => schema
.objects()
.lookup_by_key(root_table_name, |o, k| o.key_compare_with_value(k)),
None => schema.root_table(),
};
if let Some(table_object) = root_table {
if let Ok(table_pos) = verifier.get_uoffset(0) {
// Inserts -1 as object index for root table
buf_loc_to_obj_idx.insert(table_pos.try_into()?, -1);
let mut verified = vec![false; buffer.len()];
Expand Down