From 0acb61a911659537c51daf6793c67ef0c2b55bc9 Mon Sep 17 00:00:00 2001 From: pcpthm Date: Fri, 22 Mar 2019 02:22:06 +0900 Subject: Fix an arithmetic overflow in reparser --- crates/ra_syntax/src/parsing/reparsing.rs | 4 ++-- crates/ra_syntax/src/syntax_error.rs | 6 +++--- crates/ra_syntax/tests/data/reparse/fuzz-failures/0000.rs | 6 ++++++ 3 files changed, 11 insertions(+), 5 deletions(-) create mode 100644 crates/ra_syntax/tests/data/reparse/fuzz-failures/0000.rs diff --git a/crates/ra_syntax/src/parsing/reparsing.rs b/crates/ra_syntax/src/parsing/reparsing.rs index ba77a3b6c..b44cca49d 100644 --- a/crates/ra_syntax/src/parsing/reparsing.rs +++ b/crates/ra_syntax/src/parsing/reparsing.rs @@ -130,11 +130,11 @@ fn merge_errors( if e.offset() <= old_node.range().start() { res.push(e) } else if e.offset() >= old_node.range().end() { - res.push(e.add_offset(TextUnit::of_str(&edit.insert) - edit.delete.len())); + res.push(e.add_offset(TextUnit::of_str(&edit.insert), edit.delete.len())); } } for e in new_errors { - res.push(e.add_offset(old_node.range().start())); + res.push(e.add_offset(old_node.range().start(), 0.into())); } res } diff --git a/crates/ra_syntax/src/syntax_error.rs b/crates/ra_syntax/src/syntax_error.rs index bdd431742..4b8c22a57 100644 --- a/crates/ra_syntax/src/syntax_error.rs +++ b/crates/ra_syntax/src/syntax_error.rs @@ -48,10 +48,10 @@ impl SyntaxError { } } - pub fn add_offset(mut self, plus_offset: TextUnit) -> SyntaxError { + pub fn add_offset(mut self, plus_offset: TextUnit, minus_offset: TextUnit) -> SyntaxError { self.location = match self.location { - Location::Range(range) => Location::Range(range + plus_offset), - Location::Offset(offset) => Location::Offset(offset + plus_offset), + Location::Range(range) => Location::Range(range + plus_offset - minus_offset), + Location::Offset(offset) => Location::Offset(offset + plus_offset - minus_offset), }; self diff --git a/crates/ra_syntax/tests/data/reparse/fuzz-failures/0000.rs b/crates/ra_syntax/tests/data/reparse/fuzz-failures/0000.rs new file mode 100644 index 000000000..388eb74ed --- /dev/null +++ b/crates/ra_syntax/tests/data/reparse/fuzz-failures/0000.rs @@ -0,0 +1,6 @@ +0 +1 + + + +0 \ No newline at end of file -- cgit v1.2.3