From e9d01466a3bc5a109550904ae34a499e41c26da2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Hanuszczak?= Date: Mon, 28 Oct 2024 18:03:33 +0100 Subject: [PATCH] Limit line lengths in `grep_file_contents`. --- crates/rrg/src/action/grep_file_contents.rs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/crates/rrg/src/action/grep_file_contents.rs b/crates/rrg/src/action/grep_file_contents.rs index 66039171..b97ce198 100644 --- a/crates/rrg/src/action/grep_file_contents.rs +++ b/crates/rrg/src/action/grep_file_contents.rs @@ -29,18 +29,17 @@ where let file = std::fs::File::open(&args.path) .map_err(crate::session::Error::action)?; - let mut file = std::io::BufReader::new(file); + let mut file = crate::io::LineReader::new(file) + // We want to support lines only up to 1 MiB. Fleetspeak does not allow + // for messages bigger than 2 MiB anyway. + .with_max_line_len(1 * 1024 * 1024); - // TODO(@panhania): Read to a buffer of predefined size so that we do not - // allow reading lines of arbitrary length. let mut line = String::new(); let mut offset = 0; loop { - use std::io::BufRead as _; - line.clear(); - let len = match file.read_line(&mut line) { + let len = match file.read_line_lossy(&mut line) { Ok(0) => return Ok(()), Ok(len) => len, Err(error) => return Err(crate::session::Error::action(error)),