Skip to main content

LoadOptions

Struct LoadOptions 

Source
pub struct LoadOptions {
    pub max_bytes: u64,
    pub max_line_len: usize,
    pub max_sv: usize,
    pub max_nr_class: usize,
    pub max_feature_index: i32,
}
Expand description

Resource caps applied while reading LIBSVM problem and model files.

LIBSVM text formats are linear in file size, but individual fields (e.g. total_sv, feature indices, per-line token counts) can be used by a malicious file to trigger disproportionate allocation or CPU work. The Default impl returns defaults tuned for untrusted input:

FieldDefault
max_bytes64 MiB
max_line_len1 MiB
max_sv10 000 000
max_nr_class65 535
max_feature_index10 000 000

If you know the input is trusted (produced locally, read from an attestation-protected location, etc.) and you need to handle inputs larger than the defaults, call LoadOptions::trusted_input for an “unlimited” profile, or override specific fields:

use libsvm_rs::io::{load_problem_from_reader_with_options, LoadOptions};

let opts = LoadOptions {
    max_bytes: 1 << 30, // 1 GiB for a trusted bulk file
    ..LoadOptions::default()
};
let problem = load_problem_from_reader_with_options(reader, &opts)?;

Exceeding any cap returns an SvmError::ParseError (problem files) or SvmError::ModelFormatError (model files) with a message identifying the field that tripped the limit.

The default profile is intended to be panic-free for malformed text input within these caps. It is still a parser contract, not a semantic model audit: it does not verify that a loaded model came from a specific training set or that its predictions are appropriate for a deployment.

Fields§

§max_bytes: u64

Maximum total number of bytes read from the source.

§max_line_len: usize

Maximum number of bytes in a single line (excluding the terminator).

§max_sv: usize

Maximum value accepted for the total_sv header field in model files.

§max_nr_class: usize

Maximum value accepted for the nr_class header field in model files.

§max_feature_index: i32

Maximum feature index accepted in problem or model feature lists.

Implementations§

Source§

impl LoadOptions

Source

pub fn trusted_input() -> Self

Options with all caps set to the type maximum.

Use only for input that is fully trusted. Operating with unlimited caps removes the first line of defense against malformed or adversarial model / problem files. Module-level hard caps still apply to nr_class and total_sv.

Trait Implementations§

Source§

impl Clone for LoadOptions

Source§

fn clone(&self) -> LoadOptions

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for LoadOptions

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for LoadOptions

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Copy for LoadOptions

Auto Trait Implementations§

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

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.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.
Source§

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

Source§

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

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.