From 6d29e519c9c17676b849b5119eeaa247c8908c73 Mon Sep 17 00:00:00 2001 From: Sayan Nandan Date: Mon, 10 May 2021 16:53:01 +0530 Subject: [PATCH] Fix read_sizeline returning wrong error Also added more tests --- server/src/protocol/parserv2.rs | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/server/src/protocol/parserv2.rs b/server/src/protocol/parserv2.rs index 9a08653b..424463f2 100644 --- a/server/src/protocol/parserv2.rs +++ b/server/src/protocol/parserv2.rs @@ -97,10 +97,13 @@ impl<'a> Parser<'a> { // Now read the remaining line let (started_at, stopped_at) = self.read_line(); return Self::parse_into_usize(&self.buffer[started_at..stopped_at]); + } else { + // A sizeline should begin with a opt_char; this one doesn't so it's a bad packet; ugh + Err(ParseError::UnexpectedByte) } + } else { + Err(ParseError::NotEnough) } - // A sizeline should begin with a opt_char; this one doesn't so it's a bad packet; ugh - Err(ParseError::UnexpectedByte) } fn incr_cursor(&mut self) { self.cursor += 1; @@ -390,4 +393,18 @@ fn test_query_fail_not_enough() { .unwrap_err(), ParseError::NotEnough ); + let metaframe = "\r2\n*1\n".as_bytes(); + // we just got the metaframe, but there are more bytes, so this is incomplete! + assert_eq!( + Parser::new(&metaframe).parse().unwrap_err(), + ParseError::NotEnough + ); + let metaframe_and_dataframe_layout = "\r2\n*1\n#2\n&2\n".as_bytes(); + // we got the number of queries and the size of the data group, but no data; this is incomplete + assert_eq!( + Parser::new(&metaframe_and_dataframe_layout) + .parse() + .unwrap_err(), + ParseError::NotEnough + ); }