Skip to main content

ParserLimits

Struct ParserLimits 

Source
#[non_exhaustive]
pub struct ParserLimits {
Show 30 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_html_nesting_depth: usize, pub max_text_length: usize, pub max_feed_size_bytes: usize, pub max_attribute_length: usize, pub max_podcast_soundbites: usize, pub max_podcast_transcripts: usize, pub max_podcast_funding: usize, pub max_podcast_persons: usize, pub max_value_recipients: usize, pub max_podcast_alternate_enclosures: usize, pub max_podcast_alternate_enclosure_sources: usize, pub max_podcast_podroll: usize, pub max_podcast_social_interact: usize, pub max_podcast_txt: usize, pub max_podcast_follow: usize, pub max_podcast_chat: usize, pub max_podcast_value_time_splits: usize, pub max_json_extensions: usize, pub max_json_extension_memory_bytes: usize, pub max_geo_points: 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. Every field has a with_* builder that replaces only that limit.

§Examples

use feedparser_rs::ParserLimits;

let limits = ParserLimits::default();
assert_eq!(limits.max_entries, 10_000);

// Custom limits for restricted environments
let strict = ParserLimits::default()
    .with_max_entries(1_000)
    .with_max_feed_size_bytes(10 * 1024 * 1024); // 10MB
assert_eq!(strict.max_entries, 1_000);

// A value over `max_json_extension_memory_bytes` is dropped without `bozo`
let limits = ParserLimits::default().with_max_json_extension_memory_bytes(0);
let data = br#"{"version":"https://jsonfeed.org/version/1.1","_x":1}"#;
let feed = feedparser_rs::parse_with_limits(data, limits)?;
assert!(feed.feed.json_extensions.is_empty());
assert!(!feed.bozo);

Fields (Non-exhaustive)§

This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.
§max_entries: usize

Maximum 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: usize

Maximum number of links per feed (channel-level)

Prevents link bombing attacks.

Default: 100 links

§max_links_per_entry: usize

Maximum number of links per entry

Prevents link bombing in individual entries.

Default: 50 links

§max_authors: usize

Maximum number of authors per feed or entry

Default: 20 authors

§max_contributors: usize

Maximum number of contributors per feed or entry

Default: 20 contributors

§max_tags: usize

Maximum number of tags/categories per feed or entry

Default: 100 tags

§max_content_blocks: usize

Maximum number of content blocks per entry

Atom feeds can have multiple content elements.

Default: 10 content blocks

§max_enclosures: usize

Maximum number of enclosures per entry

Podcast feeds typically have 1 enclosure per episode.

Default: 20 enclosures

§max_namespaces: usize

Maximum number of XML namespaces

Prevents namespace pollution attacks.

Default: 100 namespaces

§max_nesting_depth: usize

Maximum XML nesting depth

Prevents stack overflow from deeply nested XML.

Default: 100 levels

§max_html_nesting_depth: usize

Maximum HTML tag nesting depth accepted by HTML sanitization

The HTML sanitizer’s underlying HTML5 tree builder exhibits quadratic-time behavior on pathologically deep tag nesting within a single text field (verified: multi-second slowdown from a single deeply nested <div> chain). Content nested deeper than this is escaped as plain text (&lt;/&gt;) instead of being run through the sanitizer, bounding worst-case CPU cost to linear regardless of input shape.

This is a safety bound, not a compatibility ceiling to be tuned up to match “typical” content: exceeding it degrades gracefully (the field’s HTML formatting is lost, but its text content is fully preserved and still safely escaped) rather than dropping data or erroring, so it is safe to keep conservative. Legitimate feed content — even unusually deep block-quoted reply chains or nested tables — rarely exceeds a few dozen levels; 100 (50 under the strict preset) leaves headroom above that without leaving much headroom for abuse.

Default: 100 levels

§max_text_length: usize

Maximum text field length in bytes

Prevents excessive memory from huge title/description fields.

For JSON Feed it applies to every copied string except version: titles, descriptions, summaries, content, tags and author names are truncated, while identifiers, URLs, dates, types, language tags and extensions with an over-long key are dropped, without setting bozo.

It also bounds the per-value serialized size of a captured JSON Feed extension object (see the JSON Feed extension count limit) and its node count, to the larger of 1024 and this text length divided by the size of a serde_json::Value. Every scalar, array and object is one node, and each object member adds weight for its key and slot (more for the first one, which allocates). A value over either bound is dropped entirely rather than truncated.

Default: 10 MB

§max_feed_size_bytes: usize

Maximum total feed size in bytes

The entire feed must fit within this limit.

Default: 100 MB

§max_attribute_length: usize

Maximum attribute value length in bytes

XML attributes should be reasonably sized.

Default: 64 KB

§max_podcast_soundbites: usize

Maximum number of podcast soundbites per entry

Podcast 2.0 soundbite elements for shareable clips.

Default: 10 soundbites

§max_podcast_transcripts: usize

Maximum number of podcast transcripts per entry

Podcast 2.0 transcript elements.

Default: 20 transcripts

§max_podcast_funding: usize

Maximum number of podcast funding elements per feed

Podcast 2.0 funding elements for donation links.

Default: 20 funding elements

§max_podcast_persons: usize

Maximum number of podcast person elements per entry

Podcast 2.0 person elements for hosts, guests, etc.

Default: 50 persons

§max_value_recipients: usize

Maximum number of podcast value recipients per feed

Podcast 2.0 value recipients for payment splitting. Prevents DoS from feeds with excessive recipient lists.

Default: 20 recipients

§max_podcast_alternate_enclosures: usize

Maximum number of alternate enclosures per entry

Default: 20

§max_podcast_alternate_enclosure_sources: usize

Maximum number of sources per alternate enclosure

Default: 10

§max_podcast_podroll: usize

Maximum number of podroll entries per feed

Default: 50

§max_podcast_social_interact: usize

Maximum number of socialInteract elements per entry

Default: 20

§max_podcast_txt: usize

Maximum number of txt records per feed or entry

Default: 20

§max_podcast_follow: usize

Maximum number of follow links per feed or entry

Default: 20

§max_podcast_chat: usize

Maximum number of chat references per feed or entry

Podcast 2.0 chat elements pointing to chat rooms/servers.

Default: 20

§max_podcast_value_time_splits: usize

Maximum number of value time splits per podcast:value element

Podcast 2.0 valueTimeSplit elements for routing payments over time ranges. Prevents DoS from feeds with excessive split lists.

Default: 20

§max_json_extensions: usize

Maximum number of JSON Feed extension objects captured per scope

JSON Feed permits custom object keys (starting with _ followed by a letter) anywhere in a feed; this bounds how many distinct keys are captured per feed-root or item-root scope, counted independently. When a scope has more extension keys than this limit, the surviving keys are the alphabetically-first ones, not the document-order-first ones: serde_json backs a JSON object with a BTreeMap by default (the preserve_order feature, which would switch it to an IndexMap and make truncation document-order-first, is not enabled).

Default: 100

§max_json_extension_memory_bytes: usize

Maximum estimated memory, in bytes, retained by all captured JSON Feed extensions of one document

The extension count limit and the text length limit bound each scope and value, but not their number across items. The estimate counts keys, strings and weighted nodes. Values are admitted in document order: a value that does not fit in what is left is dropped, without setting bozo. A single value can need about twice the text length limit, so raise both together.

Default: 32 MB

§max_geo_points: usize

Maximum number of points kept per GeoRSS or GML geometry

Caps the coordinate list of a line, polygon, point or box read from GeoRSS Simple or GML elements. The coordinate text itself stays bounded by the text length limit. Excess points are dropped without setting bozo, so a polygon may be left unclosed. A geometry left with fewer points than its kind needs (1 for a point, 2 for a line or box, 3 for a polygon) is dropped. W3C Basic Geo latitude/longitude pairs always have one point and are not capped.

Default: 10,000 points

Implementations§

Source§

impl ParserLimits

Source

pub const fn with_max_entries(self, value: usize) -> Self

Returns a copy with max_entries replaced.

Returns a copy with max_links_per_feed replaced.

Source

pub const fn with_max_links_per_entry(self, value: usize) -> Self

Returns a copy with max_links_per_entry replaced.

Source

pub const fn with_max_authors(self, value: usize) -> Self

Returns a copy with max_authors replaced.

Source

pub const fn with_max_contributors(self, value: usize) -> Self

Returns a copy with max_contributors replaced.

Source

pub const fn with_max_tags(self, value: usize) -> Self

Returns a copy with max_tags replaced.

Source

pub const fn with_max_content_blocks(self, value: usize) -> Self

Returns a copy with max_content_blocks replaced.

Source

pub const fn with_max_enclosures(self, value: usize) -> Self

Returns a copy with max_enclosures replaced.

Source

pub const fn with_max_namespaces(self, value: usize) -> Self

Returns a copy with max_namespaces replaced.

Source

pub const fn with_max_nesting_depth(self, value: usize) -> Self

Returns a copy with max_nesting_depth replaced.

Source

pub const fn with_max_html_nesting_depth(self, value: usize) -> Self

Returns a copy with max_html_nesting_depth replaced.

Source

pub const fn with_max_text_length(self, value: usize) -> Self

Returns a copy with max_text_length replaced.

Source

pub const fn with_max_feed_size_bytes(self, value: usize) -> Self

Returns a copy with max_feed_size_bytes replaced.

Source

pub const fn with_max_attribute_length(self, value: usize) -> Self

Returns a copy with max_attribute_length replaced.

Source

pub const fn with_max_podcast_soundbites(self, value: usize) -> Self

Returns a copy with max_podcast_soundbites replaced.

Source

pub const fn with_max_podcast_transcripts(self, value: usize) -> Self

Returns a copy with max_podcast_transcripts replaced.

Source

pub const fn with_max_podcast_funding(self, value: usize) -> Self

Returns a copy with max_podcast_funding replaced.

Source

pub const fn with_max_podcast_persons(self, value: usize) -> Self

Returns a copy with max_podcast_persons replaced.

Source

pub const fn with_max_value_recipients(self, value: usize) -> Self

Returns a copy with max_value_recipients replaced.

Source

pub const fn with_max_podcast_alternate_enclosures(self, value: usize) -> Self

Returns a copy with max_podcast_alternate_enclosures replaced.

Source

pub const fn with_max_podcast_alternate_enclosure_sources( self, value: usize, ) -> Self

Returns a copy with max_podcast_alternate_enclosure_sources replaced.

Source

pub const fn with_max_podcast_podroll(self, value: usize) -> Self

Returns a copy with max_podcast_podroll replaced.

Source

pub const fn with_max_podcast_social_interact(self, value: usize) -> Self

Returns a copy with max_podcast_social_interact replaced.

Source

pub const fn with_max_podcast_txt(self, value: usize) -> Self

Returns a copy with max_podcast_txt replaced.

Source

pub const fn with_max_podcast_follow(self, value: usize) -> Self

Returns a copy with max_podcast_follow replaced.

Source

pub const fn with_max_podcast_chat(self, value: usize) -> Self

Returns a copy with max_podcast_chat replaced.

Source

pub const fn with_max_podcast_value_time_splits(self, value: usize) -> Self

Returns a copy with max_podcast_value_time_splits replaced.

Source

pub const fn with_max_json_extensions(self, value: usize) -> Self

Returns a copy with max_json_extensions replaced.

Source

pub const fn with_max_json_extension_memory_bytes(self, value: usize) -> Self

Returns a copy with max_json_extension_memory_bytes replaced.

Source

pub const fn with_max_geo_points(self, value: usize) -> Self

Returns a copy with max_geo_points replaced.

Source§

impl ParserLimits

Source

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);
Source

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);
Source

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.

Source

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.

Source

pub const fn check_nesting_depth(&self, depth: usize) -> Result<(), LimitError>

Validates XML nesting depth

§Errors

Returns an error if nesting depth exceeds max_nesting_depth.

Source

pub const fn check_text_length(&self, length: usize) -> Result<(), LimitError>

Validates text field length

§Errors

Returns an error if text length exceeds max_text_length.

Trait Implementations§

Source§

impl Clone for ParserLimits

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Copy for ParserLimits

Source§

impl Debug for ParserLimits

Source§

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

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

impl Default for ParserLimits

Source§

fn default() -> Self

Creates default parser limits suitable for general use

These defaults are conservative and should work for most feeds, including large podcast feeds and news aggregators.

Source§

impl Eq for ParserLimits

Source§

impl PartialEq for ParserLimits

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for ParserLimits

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
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 = !

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

fn try_from(value: U) -> Result<T, !>

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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more