From 199500e9be9198b6c0699ddcce1a89a7fc168c6a Mon Sep 17 00:00:00 2001 From: tidely <43219534+tidely@users.noreply.github.com> Date: Fri, 2 Oct 2026 23:36:48 +0000 Subject: [PATCH] file_content: Fix stack overflow in encoding detection (#65102) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Summary Fix a stack overflow when searching a project in a macOS debug build. When on a debug build, opening a project which hits the `detect_encoding` code path and typing in a global search triggers an illegal instruction violation. The regression was introduced in #64549 Allocate the encoding detector’s 64 KiB buffer using a `Vec`. The inline array enlarged nested search futures and their debug-build stack frames beyond the background worker’s available stack. This hasn't hit stable yet, so I've omitted a release note. ## Testing - All tests pass - Change is extremely trivial - Project search no longer crashes with this patch To verify manually on macOS, launch Zed with `cargo run`, open a Rust project, press Cmd-Shift-F, and search for anything. ## Self-review - [x] I've reviewed my diff for quality, security, reliability, and performance. - [x] UI changes follow the [[checklist](https://zed.dev/docs/development/ui-checklist)](https://zed.dev/docs/development/ui-checklist). - [x] Tests cover the new or changed behavior. Release Notes: - N/A --- crates/file_content/src/file_content.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/file_content/src/file_content.rs b/crates/file_content/src/file_content.rs index b978f4aa40e..785611f2efc 100644 --- a/crates/file_content/src/file_content.rs +++ b/crates/file_content/src/file_content.rs @@ -88,7 +88,7 @@ pub fn decode_text(bytes: Vec) -> Result { pub async fn detect_encoding(reader: &mut (dyn Read + Send)) -> io::Result<&'static Encoding> { let mut detector = EncodingDetector::new(); - let mut block = [0; DECODING_BLOCK_BYTES]; + let mut block = vec![0; DECODING_BLOCK_BYTES]; let mut length = 0; loop { let read = match reader.read(&mut block[length..]) {