pub struct ParserLimits {Show 13 fields
pub max_entries: usize,
pub max_links_per_feed: usize,
pub max_links_per_entry: usize,
pub max_authors: usize,
pub max_contributors: usize,
pub max_tags: usize,
pub max_content_blocks: usize,
pub max_enclosures: usize,
pub max_namespaces: usize,
pub max_nesting_depth: usize,
pub max_text_length: usize,
pub max_feed_size_bytes: usize,
pub max_attribute_length: usize,
}Expand description
Parser limits for protecting against denial-of-service attacks
These limits prevent malicious or malformed feeds from causing excessive memory allocation, deep recursion, or other resource exhaustion issues.
§Examples
use feedparser_rs::ParserLimits;
let limits = ParserLimits::default();
assert_eq!(limits.max_entries, 10_000);
// Custom limits for restricted environments
let strict = ParserLimits {
max_entries: 1_000,
max_feed_size_bytes: 10 * 1024 * 1024, // 10MB
..Default::default()
};Fields§
§max_entries: usizeMaximum number of entries/items in a feed
Prevents memory exhaustion from feeds with millions of items. Typical feeds have 10-100 entries, large feeds may have up to 1000.
Default: 10,000 entries
max_links_per_feed: usizeMaximum number of links per feed (channel-level)
Prevents link bombing attacks.
Default: 100 links
max_links_per_entry: usizeMaximum number of links per entry
Prevents link bombing in individual entries.
Default: 50 links
Maximum number of authors per feed or entry
Default: 20 authors
max_contributors: usizeMaximum number of contributors per feed or entry
Default: 20 contributors
Maximum number of tags/categories per feed or entry
Default: 100 tags
max_content_blocks: usizeMaximum number of content blocks per entry
Atom feeds can have multiple content elements.
Default: 10 content blocks
max_enclosures: usizeMaximum number of enclosures per entry
Podcast feeds typically have 1 enclosure per episode.
Default: 20 enclosures
max_namespaces: usizeMaximum number of XML namespaces
Prevents namespace pollution attacks.
Default: 100 namespaces
max_nesting_depth: usizeMaximum XML nesting depth
Prevents stack overflow from deeply nested XML.
Default: 100 levels
max_text_length: usizeMaximum text field length in bytes
Prevents excessive memory from huge title/description fields.
Default: 10 MB
max_feed_size_bytes: usizeMaximum total feed size in bytes
The entire feed must fit within this limit.
Default: 100 MB
max_attribute_length: usizeMaximum attribute value length in bytes
XML attributes should be reasonably sized.
Default: 64 KB
Implementations§
Source§impl ParserLimits
impl ParserLimits
Sourcepub const fn strict() -> Self
pub const fn strict() -> Self
Creates strict limits for resource-constrained environments
Use this for embedded systems or when parsing untrusted feeds with minimal resources.
§Examples
use feedparser_rs::ParserLimits;
let limits = ParserLimits::strict();
assert_eq!(limits.max_entries, 1_000);Sourcepub const fn permissive() -> Self
pub const fn permissive() -> Self
Creates permissive limits for trusted feeds
Use this only for feeds from trusted sources where you expect large data volumes (e.g., feed archives).
§Examples
use feedparser_rs::ParserLimits;
let limits = ParserLimits::permissive();
assert_eq!(limits.max_entries, 100_000);Sourcepub const fn check_feed_size(&self, size: usize) -> Result<(), LimitError>
pub const fn check_feed_size(&self, size: usize) -> Result<(), LimitError>
Validates that a feed size is within limits
Call this before starting to parse a feed.
§Errors
Returns an error if the feed exceeds max_feed_size_bytes.
Sourcepub const fn check_collection_size(
&self,
current: usize,
limit: usize,
name: &'static str,
) -> Result<(), LimitError>
pub const fn check_collection_size( &self, current: usize, limit: usize, name: &'static str, ) -> Result<(), LimitError>
Validates that a collection size is within limits
Use this during parsing to check collection sizes.
§Errors
Returns an error if the collection size exceeds the specified limit.
Sourcepub const fn check_nesting_depth(&self, depth: usize) -> Result<(), LimitError>
pub const fn check_nesting_depth(&self, depth: usize) -> Result<(), LimitError>
Sourcepub const fn check_text_length(&self, length: usize) -> Result<(), LimitError>
pub const fn check_text_length(&self, length: usize) -> Result<(), LimitError>
Trait Implementations§
Source§impl Clone for ParserLimits
impl Clone for ParserLimits
Source§fn clone(&self) -> ParserLimits
fn clone(&self) -> ParserLimits
1.0.0§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for ParserLimits
impl Debug for ParserLimits
Source§impl Default for ParserLimits
impl Default for ParserLimits
Source§impl PartialEq for ParserLimits
impl PartialEq for ParserLimits
impl Copy for ParserLimits
impl Eq for ParserLimits
impl StructuralPartialEq for ParserLimits
Auto Trait Implementations§
impl Freeze for ParserLimits
impl RefUnwindSafe for ParserLimits
impl Send for ParserLimits
impl Sync for ParserLimits
impl Unpin for ParserLimits
impl UnwindSafe for ParserLimits
Blanket Implementations§
§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§unsafe fn clone_to_uninit(&self, dest: *mut u8)
unsafe fn clone_to_uninit(&self, dest: *mut u8)
clone_to_uninit)