Merge pull request #273 from tree-sitter/vmg/byte-overflow

binding: Add overflow checks when slicing in `parse`
This commit is contained in:
Max Brunsfeld 2019-02-11 09:44:09 -08:00 committed by GitHub
commit 216ff5c3d5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -229,7 +229,8 @@ impl Parser {
pub fn parse(&mut self, input: impl AsRef<[u8]>, old_tree: Option<&Tree>) -> Option<Tree> {
let bytes = input.as_ref();
self.parse_with(&mut |i, _| &bytes[i..], old_tree)
let len = bytes.len();
self.parse_with(&mut |i, _| if i < len { &bytes[i..] } else { &[] }, old_tree)
}
pub fn parse_utf16(
@ -238,7 +239,8 @@ impl Parser {
old_tree: Option<&Tree>,
) -> Option<Tree> {
let code_points = input.as_ref();
self.parse_utf16_with(&mut |i, _| &code_points[i..], old_tree)
let len = code_points.len();
self.parse_utf16_with(&mut |i, _| if i < len { &code_points[i..] } else { &[] }, old_tree)
}
pub fn parse_with<'a, T: FnMut(usize, Point) -> &'a [u8]>(