pub struct FuzzedDataProvider { /* private fields */ }
Expand description

| In addition to the comments below, the | API is also briefly documented at | https://github.com/google/fuzzing/blob/master/docs/split-inputs.md#fuzzed-data-provider |

Implementations§

source§

impl FuzzedDataProvider

source

pub fn new(data: *const u8, size: usize) -> Self

| |data| is an array of length |size| that the | FuzzedDataProvider wraps to provide more | granular access. |data| must outlive the | FuzzedDataProvider.

source

pub fn remaining_bytes(&mut self) -> usize

| Reports the remaining bytes available | for fuzzed input. |

source

pub fn consume_bytes<T>(&mut self, num_bytes: usize) -> Vec<T>

Returns a std::vector containingnum_bytesof
input data. If fewer thannum_bytesof data
remain, returns a shorter std::vector
containing all of the data that’s left. Can be
used with any byte sized type, such as char,
unsigned char, uint8_t, etc.
source

pub fn consume_bytes_with_terminator<T: Zero>( &mut self, num_bytes: usize, terminator: Option<T> ) -> Vec<T>

| Similar to |ConsumeBytes|, but also appends the | terminator value at the end of the resulting | vector. Useful, when a mutable null-terminated | C-string is needed, for example. But that is | a rare case. Better avoid it, if possible, and | prefer using |ConsumeBytes| or | |ConsumeBytesAsString| methods.

source

pub fn consume_remaining_bytes<T>(&mut self) -> Vec<T>

| Returns a std::vector containing all | remaining bytes of the input data. |

source

pub fn consume_bytes_as_string(&mut self, num_bytes: usize) -> String

| Methods returning strings. Use only when you | need a std::string or a null terminated | C-string. Otherwise, prefer the methods | returning std::vector. |
Returns a std::string containingnum_bytesof
input data. Using this and.c_str()on the
resulting string is the best way to get an
immutable null-terminated C string. If fewer
thannum_bytesof data remain, returns
a shorter std::string containing all of the
data that’s left.
source

pub fn consume_random_length_string_with_maxlen( &mut self, max_length: usize ) -> String

| Returns a std::string of length from 0 to | |max_length|. When it runs out of input data, | returns what remains of the input. Designed to | be more stable with respect to a fuzzer | inserting characters than just picking a random | length and then consuming that many bytes with | |ConsumeBytes|.

source

pub fn consume_random_length_string(&mut self) -> String

| Returns a std::string of length from | 0 to remaining_bytes_|. |

source

pub fn consume_remaining_bytes_as_string(&mut self) -> String

| Returns a std::string containing all remaining | bytes of the input data. | | Prefer using |ConsumeRemainingBytes| unless you | actually need a std::string object.

source

pub fn consume_integral<T>(&mut self) -> T

| Methods returning integer values. |

| Returns a number in the range [Type’s min, | Type’s max]. The value might not be uniformly | distributed in the given range. If there’s no | input data left, always returns |min|.

source

pub fn consume_integral_in_range<T>(&mut self, min: T, max: T) -> T

| Returns a number in the range [min, max] by | consuming bytes from the input data. The value | might not be uniformly distributed in the given | range. If there’s no input data left, always | returns |min|. |min| must be less than or equal | to |max|.

source

pub fn consume_floating_point<T>(&mut self) -> T

| Methods returning floating point values. |

| Returns a floating point value in the range | [Type’s lowest, Type’s max] by consuming bytes | from the input data. If there’s no input data | left, always returns approximately 0.

source

pub fn consume_floating_point_in_range<T>(&mut self, min: T, max: T) -> T

| Returns a floating point value in the given | range by consuming bytes from the input | data. If there’s no input data left, returns | |min|. Note that |min| must be less than or | equal to |max|.

source

pub fn consume_probability<T>(&mut self) -> T

| Returns a floating point number in the | range [0.0, 1.0]. If there’s no input | data left, always returns 0. | | 0 <= return value <= 1. |

source

pub fn consume_bool(&mut self) -> bool

| Reads one byte and returns a bool, or | false when no data remains. |

source

pub fn consume_enum<T>(&mut self) -> T

| Returns a value chosen from the given | enum. |

| Returns an enum value. The enum must start at | 0 and be contiguous. It must also contain | |kMaxValue| aliased to its largest (inclusive) | value. Such as: enum class Foo { SomeValue, | OtherValue, kMaxValue = OtherValue };

source

pub fn pick_value_in_array<T, const size: usize>( &mut self, array: &[T; size] ) -> T

| Returns a copy of the value selected | from the given fixed-size |array|. |

source

pub fn pick_value_in_array_with_initlist<T>( &mut self, list: InitializerList<T> ) -> T

source

pub fn consume_data( &mut self, destination: *mut c_void, num_bytes: usize ) -> usize

| Writes data to the given destination | and returns number of bytes written. |

| Writes |num_bytes| of input data to the given | destination pointer. If there is not enough | data left, writes all remaining bytes. Return | value is the number of bytes written. | | In general, it’s better to avoid using this | function, but it may be useful in cases when | it’s necessary to fill a certain buffer or | object with fuzzing data.

source

pub fn copy_and_advance(&mut self, destination: *mut c_void, num_bytes: usize)

| Private methods. |

source

pub fn advance(&mut self, num_bytes: usize)

source

pub fn consume_bytes_with_size<T>( &mut self, size: usize, num_bytes: usize ) -> Vec<T>

source

pub fn convert_unsigned_to_signed<TS, TU>(&mut self, value: TU) -> TS

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T, U> CastInto<U> for Twhere U: CastFrom<T>,

§

unsafe fn cast_into(self) -> U

Performs the conversion. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> Pointable for T

§

const ALIGN: usize = mem::align_of::<T>()

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
§

impl<T> StaticUpcast<T> for T

§

unsafe fn static_upcast(ptr: Ptr<T>) -> Ptr<T>

Convert type of a const pointer. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

§

fn vzip(self) -> V