diff options
author | Christian Duerr <contact@christianduerr.com> | 2018-08-11 16:52:13 +0200 |
---|---|---|
committer | Joe Wilm <jwilm@users.noreply.github.com> | 2018-08-13 09:01:23 -0700 |
commit | b684bb8bd80637da85693daff48f3a84bb073a0c (patch) | |
tree | c0eddf46778a498d467ad62d1f4ae53dcfc3cf79 | |
parent | fe116505000826c42f6f0ac2e598d7fe19217588 (diff) | |
download | r-alacritty-vte-b684bb8bd80637da85693daff48f3a84bb073a0c.tar.gz r-alacritty-vte-b684bb8bd80637da85693daff48f3a84bb073a0c.tar.bz2 r-alacritty-vte-b684bb8bd80637da85693daff48f3a84bb073a0c.zip |
Fix off-by-one error when parsing CSI escapes
The CSI escape sequences are limited to 16 parameters using the
`MAX_PARAMS` constant.
To make sure no more params are parsed, the CSI parser stops when the
parameter index reaches `MAX_PARAMS`, however this means that it stops
at index 16, which means that the number of params would be 17 since
arrays start at 0.
To fix this off-by-one error the CSI parser now stops when the index
reaches `MAX_PARAMS - 1`, which means it will stop when the index
reaches the last element in an array with `MAX_PARAMS` number of
elements.
This fixes jwilm/alacritty#1505.
-rw-r--r-- | src/lib.rs | 5 |
1 files changed, 3 insertions, 2 deletions
@@ -332,7 +332,7 @@ impl Parser { // Completed a param let idx = self.num_params; - if idx == MAX_PARAMS { + if idx == MAX_PARAMS - 1 { return; } @@ -537,7 +537,7 @@ mod tests { fn parse_csi_max_params() { use MAX_PARAMS; - static INPUT: &'static [u8] = b"\x1b[;;;;;;;;;;;;;;;;;p"; + static INPUT: &'static [u8] = b"\x1b[1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;p"; // Create dispatcher and check state let mut dispatcher = CsiDispatcher::default(); @@ -588,6 +588,7 @@ mod tests { assert_eq!(dispatcher.params[0], &[i64::MAX as i64]); } + #[test] fn parse_osc_with_utf8_arguments() { static INPUT: &'static [u8] = &[ |