Oregami
Repositories/oxedyne/fe2o3

oxedyne/fe2o3/fe2o3_file/src/limits.rs

1.7 KiB, 13 runs

created by r1403719401:77602, which is this file's identity for as long as the history lasts, whatever it is later renamed to

download · who wrote it · its history

1//! The bounds this crate keeps on input it did not write, as configuration.
2//!
3//! A workbook or an ignore file may come from anyone, and the size of what it unfolds into is
4//! decided by the file. These are the caller's answer to "how much is too much", embedded in an
5//! app's own configuration; [`Limits::default`] is the answer for an app that gives none.
6
7use oxedyne_fe2o3_core::prelude::*;
8use oxedyne_fe2o3_jdat::{
9 prelude::*,
10 cfg::Config,
11};
12
13use std::collections::BTreeMap; // the ToDatMap derive names it
14
15#[derive(Clone, Debug, Eq, PartialEq, FromDatMap, ToDatMap)]
16pub struct Limits {
17 // Cells one workbook read may hold, over all its sheets. A row costs one, and so does each empty
18 // cell a reader fills in to keep a later cell in its column.
19 pub sheet_cells: u64,
20 // Bytes of text and formulae one workbook read may hold, over all its sheets. A repeated or
21 // shared cell is paid for at each place it is laid down.
22 pub sheet_bytes: u64,
23 // Bytes an ignore file, or git's global excludes, may hold before it is skipped unread.
24 pub ignore_file_bytes: u64,
25}
26
27impl Default for Limits {
28 fn default() -> Self {
29 Self {
30 sheet_cells: 4_000_000,
31 sheet_bytes: 134_217_728, // 128 MiB, above the content part's inflate cap
32 ignore_file_bytes: 1_048_576, // 1 MiB
33 }
34 }
35}
36
37impl Config for Limits {
38 fn check_and_fix(&mut self) -> Outcome<()> {
39 for (name, v) in [
40 ("sheet_cells", self.sheet_cells),
41 ("sheet_bytes", self.sheet_bytes),
42 ("ignore_file_bytes", self.ignore_file_bytes),
43 ] {
44 if v == 0 {
45 return Err(err!("The file limit '{}' is zero, which would refuse every file.", name;
46 Invalid, Input, Configuration));
47 }
48 }
49 Ok(())
50 }
51}