diff --git a/codec/src/lib.rs b/codec/src/lib.rs index 425f9d329..7869a47bd 100644 --- a/codec/src/lib.rs +++ b/codec/src/lib.rs @@ -441,7 +441,7 @@ macro_rules! pdu { /// The overall version of the codec. /// This must be bumped when backwards incompatible changes /// are made to the types and protocol. -pub const CODEC_VERSION: usize = 44; +pub const CODEC_VERSION: usize = 45; // Defines the Pdu enum. // Each struct has an explicit identifying number. diff --git a/docs/changelog.md b/docs/changelog.md index e66e9d9f5..f38275423 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -197,6 +197,7 @@ As features stabilize some brief notes about them will accumulate here. @mgpinf! #6248 #5806 #5346 * Deadlock when a domain detaches due to SSH timeout. Thanks to @joexue! #6749 #6750 +* Panic when rewrapping very very long lines. #6729 #### Updated * Bundled conpty.dll and OpenConsole.exe to build 1.22.250204002.nupkg diff --git a/termwiz/src/surface/line/clusterline.rs b/termwiz/src/surface/line/clusterline.rs index b6631b3b4..a4f523b6d 100644 --- a/termwiz/src/surface/line/clusterline.rs +++ b/termwiz/src/surface/line/clusterline.rs @@ -31,7 +31,7 @@ pub(crate) struct ClusteredLine { is_double_wide: Option>, clusters: Vec, /// Length, measured in cells - len: u16, + len: u32, last_cell_width: Option, } @@ -176,16 +176,25 @@ impl ClusteredLine { } pub fn append_grapheme(&mut self, text: &str, cell_width: usize, attrs: CellAttributes) { + let cell_width = cell_width as u16; let new_cluster = match self.clusters.last() { - Some(cluster) => cluster.attrs != attrs, + Some(cluster) => { + if cluster.attrs != attrs { + true + } else { + // If we overflow the max length of a run, + // then we need a new cluster + let (_, did_overflow) = cluster.cell_width.overflowing_add(cell_width); + did_overflow + } + } None => true, }; let new_cell_index = self.len as usize; - let cell_width = cell_width as u16; if new_cluster { self.clusters.push(Cluster { attrs, cell_width }); } else if let Some(cluster) = self.clusters.last_mut() { - cluster.cell_width += cell_width as u16; + cluster.cell_width += cell_width; } self.text.push_str(text); @@ -205,16 +214,25 @@ impl ClusteredLine { self.is_double_wide.replace(bitset); } self.last_cell_width = NonZeroU8::new(cell_width as u8); - self.len += cell_width; + self.len += cell_width as u32; } pub fn append(&mut self, cell: Cell) { + let cell_width = cell.width() as u16; let new_cluster = match self.clusters.last() { - Some(cluster) => cluster.attrs != *cell.attrs(), + Some(cluster) => { + if cluster.attrs != *cell.attrs() { + true + } else { + // If we overflow the max length of a run, + // then we need a new cluster + let (_, did_overflow) = cluster.cell_width.overflowing_add(cell_width); + did_overflow + } + } None => true, }; let new_cell_index = self.len as usize; - let cell_width = cell.width() as u16; if new_cluster { self.clusters.push(Cluster { attrs: (*cell.attrs()).clone(), @@ -241,7 +259,7 @@ impl ClusteredLine { self.is_double_wide.replace(bitset); } self.last_cell_width = NonZeroU8::new(cell_width as u8); - self.len += cell_width; + self.len += cell_width as u32; } pub fn prune_trailing_blanks(&mut self) -> bool {