From 02fc0a45dd1a34368c5a5526756c5416cf997b83 Mon Sep 17 00:00:00 2001 From: Justus Winter Date: Fri, 22 Jan 2021 08:02:20 +0100 Subject: sq: Make limit explicit. --- sq/src/sq.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/sq/src/sq.rs b/sq/src/sq.rs index 02706a22..a62c4922 100644 --- a/sq/src/sq.rs +++ b/sq/src/sq.rs @@ -220,13 +220,16 @@ fn parse_armor_kind(kind: Option<&str>) -> Option { } } +/// How much data to look at when detecting armor kinds. +const ARMOR_DETECTION_LIMIT: u64 = 1 << 24; + /// Peeks at the first packet to guess the type. /// /// Returns the given reader unchanged. If the detection fails, /// armor::Kind::File is returned as safe default. fn detect_armor_kind(input: Box>) -> (Box>, armor::Kind) { - let mut dup = Limitor::new(Dup::new(input), 1 << 24).as_boxed(); + let mut dup = Limitor::new(Dup::new(input), ARMOR_DETECTION_LIMIT).as_boxed(); let kind = 'detection: loop { if let Ok(ppr) = PacketParser::from_reader(&mut dup) { if let PacketParserResult::Some(pp) = ppr { @@ -461,7 +464,7 @@ fn main() -> Result<()> { // Peek at the data. If it looks like it is armored // data, avoid armoring it again. - let mut dup = Limitor::new(Dup::new(input), 1 << 24); + let mut dup = Limitor::new(Dup::new(input), ARMOR_DETECTION_LIMIT); let (already_armored, have_kind) = { let mut reader = armor::Reader::new(&mut dup, -- cgit v1.2.3