Fix unbounded zerowidth character limit

Alacritty was using a `Vec` without limits to store zerowidth
characters, making it possible to exhaust system memory by writing a
large number of these characters to a single cell.

Problem Example:
    echo -en a; (while true; do echo -en '\xcc\x81'; done)
This commit is contained in:
Daniel Fox Franke authored and GitHub committed 2026-08-26 04:17:18 +00:00
1 parent 7dd7b5b09e
commit ede2ac144d
5 files changed
+17 -3

No files matched your search

+1
View File
@@ -20,6 +20,7 @@ Notable changes to the `alacritty_terminal` crate are documented in its
- Spurious "Failed to set new owner of XCB selection" warnings on X11
- Lacking permissions to launch software sending Apple events
- Off-by-one in vi mode ParagraphUp action
- Unbounded per-cell memory usage for zero-width cells
## 0.17.0
Generated
+4
View File
@@ -97,6 +97,7 @@ dependencies = [
name = "alacritty_terminal"
version = "0.26.1-dev"
dependencies = [
"arrayvec",
"base64",
"bitflags 2.9.4",
"home",
@@ -205,6 +206,9 @@ name = "arrayvec"
version = "0.7.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7c02d123df017efcdfbd739ef81735b36c5ba83ec3c59c80a9d7ecc718f92e50"
dependencies = [
"serde",
]
[[package]]
name = "as-raw-xcb-connection"
+1
View File
@@ -14,6 +14,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Panic when the PTY could not be set to non-blocking
- Off-by-one in ViMotion::ParagraphUp
- Unbounded per-cell memory usage for zero-width cells
## 0.26.0
+1
View File
@@ -15,6 +15,7 @@ default = ["serde"]
serde = ["dep:serde", "bitflags/serde", "vte/serde"]
[dependencies]
arrayvec = { version = "0.7.2", features = ["serde"] }
base64 = "0.22.0"
bitflags = "2.4.1"
home = "0.5.5"
+10 -3
View File
@@ -1,6 +1,7 @@
use std::sync::Arc;
use std::sync::atomic::{AtomicU32, Ordering};
use arrayvec::ArrayVec;
use bitflags::bitflags;
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
@@ -9,6 +10,12 @@ use crate::grid::{self, GridCell};
use crate::index::Column;
use crate::vte::ansi::{Color, Hyperlink as VteHyperlink, NamedColor};
/// Maximum number of zerowidth characters to retain per grid cell.
///
/// This enforces an upper bound on memory usage per cell, to ensure
/// malicous applications cannot use this as a DoS vector.
const MAX_ZEROWIDTH_CHARS: usize = 9;
bitflags! {
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
@@ -123,7 +130,7 @@ impl ResetDiscriminant<Color> for Cell {
#[derive(Default, Debug, Clone, Eq, PartialEq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct CellExtra {
zerowidth: Vec<char>,
zerowidth: ArrayVec<char, MAX_ZEROWIDTH_CHARS>,
underline_color: Option<Color>,
hyperlink: Option<Hyperlink>,
}
@@ -163,7 +170,7 @@ impl Cell {
#[inline]
pub fn push_zerowidth(&mut self, character: char) {
let extra = self.extra.get_or_insert(Default::default());
Arc::make_mut(extra).zerowidth.push(character);
let _ = Arc::make_mut(extra).zerowidth.try_push(character);
}
/// Remove all wide char data from a cell.
@@ -171,7 +178,7 @@ impl Cell {
pub fn clear_wide(&mut self) {
self.flags.remove(Flags::WIDE_CHAR);
if let Some(extra) = self.extra.as_mut() {
Arc::make_mut(extra).zerowidth = Vec::new();
Arc::make_mut(extra).zerowidth = ArrayVec::new();
}
self.c = ' ';
}