Skip to main content

rightkit_docs/
limits.rs

1//! Hostile-input caps, enforced inside the crate before any parser sees a byte.
2
3use serde::{Deserialize, Serialize};
4
5/// Caps on one input file. The defaults suit documents a person or an agent opens; raise them
6/// per call, never process-wide.
7#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
8#[serde(rename_all = "camelCase", default)]
9pub struct Limits {
10    /// Compressed (on-disk) size of the input.
11    pub max_input_bytes: u64,
12    /// Total decompressed bytes of every part of a package.
13    pub max_total_bytes: u64,
14    /// Decompressed bytes of any one part.
15    pub max_part_bytes: u64,
16    /// Entries in a package.
17    pub max_entries: usize,
18    /// Decompressed to compressed ratio, applied to any part over 1 MiB and to the package as a
19    /// whole once it is over 4 MiB. Honest spreadsheets with repeated rows reach 50:1.
20    pub max_ratio: u64,
21    /// Pages a PDF may have.
22    pub max_pdf_pages: usize,
23}
24
25impl Default for Limits {
26    fn default() -> Self {
27        Self {
28            max_input_bytes: 64 << 20,
29            max_total_bytes: 256 << 20,
30            max_part_bytes: 64 << 20,
31            max_entries: 10_000,
32            max_ratio: 200,
33            max_pdf_pages: 5_000,
34        }
35    }
36}