diff options
author | Christian Duerr <contact@christianduerr.com> | 2022-05-18 01:58:09 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-05-17 23:58:09 +0000 |
commit | 586a5fee5a1dd578dae857a45689aece7f03edeb (patch) | |
tree | 02a7f94e0dad512fb4b4f03418484931072eedb3 | |
parent | dfac57ef3fdd5ddc884ce7d7559137c5123bae3e (diff) | |
download | r-alacritty-vte-586a5fee5a1dd578dae857a45689aece7f03edeb.tar.gz r-alacritty-vte-586a5fee5a1dd578dae857a45689aece7f03edeb.tar.bz2 r-alacritty-vte-586a5fee5a1dd578dae857a45689aece7f03edeb.zip |
Fix filled params list ending with subparam
When the params list for the CSI/DCS escapes is filled with all 32
parameters but ends in a subparameter, it would not properly stage the
length of the added subparameters causing the param iterator to get
stuck in place.
To ensure we always update the subparameter length even when no
parameter is staged after it, the length of subparameters is now updated
immediately while the subparameters itself are added.
Fixes #77.
-rw-r--r-- | CHANGELOG.md | 1 | ||||
-rw-r--r-- | src/lib.rs | 24 | ||||
-rw-r--r-- | src/params.rs | 1 |
3 files changed, 25 insertions, 1 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index df9e8f0..b658cb3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ CHANGELOG ## Unreleased - Minimum rust version has been bumped to 1.56.0 +- Fixed infinite loop in `Params` iterator when 32nd parameter is a subparameter ## 0.10.1 @@ -307,7 +307,7 @@ impl Parser { ); }, Action::EscDispatch => { - performer.esc_dispatch(self.intermediates(), self.ignoring, byte) + performer.esc_dispatch(self.intermediates(), self.ignoring, byte); }, Action::Collect => { if self.intermediate_idx == MAX_INTERMEDIATES { @@ -899,6 +899,28 @@ mod tests { _ => panic!("expected esc sequence"), } } + + #[test] + fn params_buffer_filled_with_subparam() { + static INPUT: &[u8] = b"\x1b[::::::::::::::::::::::::::::::::x\x1b"; + let mut dispatcher = Dispatcher::default(); + let mut parser = Parser::new(); + + for byte in INPUT { + parser.advance(&mut dispatcher, *byte); + } + + assert_eq!(dispatcher.dispatched.len(), 1); + match &dispatcher.dispatched[0] { + Sequence::Csi(params, intermediates, ignore, c) => { + assert_eq!(intermediates, &[]); + assert_eq!(params, &[[0; 32]]); + assert_eq!(c, &'x'); + assert!(ignore); + }, + _ => panic!("expected csi sequence"), + } + } } #[cfg(all(feature = "nightly", test))] diff --git a/src/params.rs b/src/params.rs index ca6ba48..608c040 100644 --- a/src/params.rs +++ b/src/params.rs @@ -68,6 +68,7 @@ impl Params { /// Add an additional subparameter to the current parameter. #[inline] pub(crate) fn extend(&mut self, item: u16) { + self.subparams[self.len - self.current_subparams as usize] = self.current_subparams + 1; self.params[self.len] = item; self.current_subparams += 1; self.len += 1; |