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:
| Field | Default |
|---|---|
max_bytes | 64 MiB |
max_line_len | 1 MiB |
max_sv | 10 000 000 |
max_nr_class | 65 535 |
max_feature_index | 10 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: u64Maximum total number of bytes read from the source.
max_line_len: usizeMaximum number of bytes in a single line (excluding the terminator).
max_sv: usizeMaximum value accepted for the total_sv header field in model files.
max_nr_class: usizeMaximum value accepted for the nr_class header field in model files.
max_feature_index: i32Maximum feature index accepted in problem or model feature lists.
Implementations§
Source§impl LoadOptions
impl LoadOptions
Sourcepub fn trusted_input() -> Self
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
impl Clone for LoadOptions
Source§fn clone(&self) -> LoadOptions
fn clone(&self) -> LoadOptions
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more