aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpcpthm <[email protected]>2019-03-21 17:22:06 +0000
committerpcpthm <[email protected]>2019-03-21 23:09:11 +0000
commit0acb61a911659537c51daf6793c67ef0c2b55bc9 (patch)
tree1eda85ba930c16ae378be638d392c4a624bd9429
parent4c7142d0c9be90c8947deb788993d903b2e0a5d1 (diff)
Fix an arithmetic overflow in reparser
-rw-r--r--crates/ra_syntax/src/parsing/reparsing.rs4
-rw-r--r--crates/ra_syntax/src/syntax_error.rs6
-rw-r--r--crates/ra_syntax/tests/data/reparse/fuzz-failures/0000.rs6
3 files changed, 11 insertions, 5 deletions
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(
130 if e.offset() <= old_node.range().start() { 130 if e.offset() <= old_node.range().start() {
131 res.push(e) 131 res.push(e)
132 } else if e.offset() >= old_node.range().end() { 132 } else if e.offset() >= old_node.range().end() {
133 res.push(e.add_offset(TextUnit::of_str(&edit.insert) - edit.delete.len())); 133 res.push(e.add_offset(TextUnit::of_str(&edit.insert), edit.delete.len()));
134 } 134 }
135 } 135 }
136 for e in new_errors { 136 for e in new_errors {
137 res.push(e.add_offset(old_node.range().start())); 137 res.push(e.add_offset(old_node.range().start(), 0.into()));
138 } 138 }
139 res 139 res
140} 140}
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 {
48 } 48 }
49 } 49 }
50 50
51 pub fn add_offset(mut self, plus_offset: TextUnit) -> SyntaxError { 51 pub fn add_offset(mut self, plus_offset: TextUnit, minus_offset: TextUnit) -> SyntaxError {
52 self.location = match self.location { 52 self.location = match self.location {
53 Location::Range(range) => Location::Range(range + plus_offset), 53 Location::Range(range) => Location::Range(range + plus_offset - minus_offset),
54 Location::Offset(offset) => Location::Offset(offset + plus_offset), 54 Location::Offset(offset) => Location::Offset(offset + plus_offset - minus_offset),
55 }; 55 };
56 56
57 self 57 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 @@
10
21
3
4
5
60 \ No newline at end of file