Skip to main content

read_capped

Function read_capped 

Source
pub fn read_capped(path: &Path, max_bytes: u64) -> Result<String>
Expand description

Read a file, refusing to load more than max_bytes. Unbounded fs::read_to_string on attacker-controlled JSON is a denial-of- service primitive (a 4 GiB file gets loaded into RAM); every JSON state file we own should route through this. Returns ErrorKind::InvalidData when the file is too large so callers can distinguish from missing/permission errors.