mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-07 13:53:38 +00:00
Rust Flatbuffers Verifier (#6269)
* Updated comments and fixed a fundemental type error. * bump rust flatbuffers semver * Initial commit with verifier, need to clean up * Verifier tested. Needs clean up and refactoring. * Display for InvalidFlatbuffer and better errors for strings * SimpleToVerify, some refactoring * Combined VerifierType TableAccessorFuncBody into FollowType * scrub todos * Update Rust get_root functions. There are 6 variants, with verifier options, default verifier options and no verification "fast". * Rename root fns * inline * Update to use thiserror * fix for bad compiler * improve error formatting * Replace multiply with saturating_multiply * saturating adds too * Add docs disclaiming experimental verification system Co-authored-by: Casper Neo <cneo@google.com>
This commit is contained in:
@@ -72,7 +72,8 @@ impl<'a> flatbuffers::Follow<'a> for FromInclude {
|
||||
type Inner = Self;
|
||||
#[inline]
|
||||
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
Self(flatbuffers::read_scalar_at::<i64>(buf, loc))
|
||||
let b = flatbuffers::read_scalar_at::<i64>(buf, loc);
|
||||
Self(b)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -87,14 +88,27 @@ impl flatbuffers::Push for FromInclude {
|
||||
impl flatbuffers::EndianScalar for FromInclude {
|
||||
#[inline]
|
||||
fn to_little_endian(self) -> Self {
|
||||
Self(i64::to_le(self.0))
|
||||
let b = i64::to_le(self.0);
|
||||
Self(b)
|
||||
}
|
||||
#[inline]
|
||||
fn from_little_endian(self) -> Self {
|
||||
Self(i64::from_le(self.0))
|
||||
let b = i64::from_le(self.0);
|
||||
Self(b)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> flatbuffers::Verifiable for FromInclude {
|
||||
#[inline]
|
||||
fn run_verifier<'o, 'b>(
|
||||
v: &mut flatbuffers::Verifier<'o, 'b>, pos: usize
|
||||
) -> Result<(), flatbuffers::InvalidFlatbuffer> {
|
||||
use self::flatbuffers::Verifiable;
|
||||
i64::run_verifier(v, pos)
|
||||
}
|
||||
}
|
||||
|
||||
impl flatbuffers::SimpleToVerifyInSlice for FromInclude {}
|
||||
// struct Unused, aligned to 4
|
||||
#[repr(C, align(4))]
|
||||
#[derive(Clone, Copy, PartialEq)]
|
||||
@@ -109,6 +123,7 @@ impl std::fmt::Debug for Unused {
|
||||
}
|
||||
}
|
||||
|
||||
impl flatbuffers::SimpleToVerifyInSlice for Unused {}
|
||||
impl flatbuffers::SafeSliceAccess for Unused {}
|
||||
impl<'a> flatbuffers::Follow<'a> for Unused {
|
||||
type Inner = &'a Unused;
|
||||
@@ -146,7 +161,15 @@ impl<'b> flatbuffers::Push for &'b Unused {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
impl<'a> flatbuffers::Verifiable for Unused {
|
||||
#[inline]
|
||||
fn run_verifier<'o, 'b>(
|
||||
v: &mut flatbuffers::Verifier<'o, 'b>, pos: usize
|
||||
) -> Result<(), flatbuffers::InvalidFlatbuffer> {
|
||||
use self::flatbuffers::Verifiable;
|
||||
v.in_buffer::<Self>(pos)
|
||||
}
|
||||
}
|
||||
impl Unused {
|
||||
pub fn new(_a: i32) -> Self {
|
||||
Unused {
|
||||
@@ -194,10 +217,22 @@ impl<'a> TableB<'a> {
|
||||
|
||||
#[inline]
|
||||
pub fn a(&self) -> Option<super::super::TableA<'a>> {
|
||||
self._tab.get::<flatbuffers::ForwardsUOffset<super::super::TableA<'a>>>(TableB::VT_A, None)
|
||||
self._tab.get::<flatbuffers::ForwardsUOffset<super::super::TableA>>(TableB::VT_A, None)
|
||||
}
|
||||
}
|
||||
|
||||
impl flatbuffers::Verifiable for TableB<'_> {
|
||||
#[inline]
|
||||
fn run_verifier<'o, 'b>(
|
||||
v: &mut flatbuffers::Verifier<'o, 'b>, pos: usize
|
||||
) -> Result<(), flatbuffers::InvalidFlatbuffer> {
|
||||
use self::flatbuffers::Verifiable;
|
||||
v.visit_table(pos)?
|
||||
.visit_field::<flatbuffers::ForwardsUOffset<super::super::TableA>>(&"a", Self::VT_A, false)?
|
||||
.finish();
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
pub struct TableBArgs<'a> {
|
||||
pub a: Option<flatbuffers::WIPOffset<super::super::TableA<'a>>>,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user