file_content: Fix stack overflow in encoding detection (#65102)

## 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
This commit is contained in:
tidely
2026-10-02 23:36:48 +00:00
committed by GitHub
parent c83abe7d0e
commit 199500e9be
+1 -1
View File
@@ -88,7 +88,7 @@ pub fn decode_text(bytes: Vec<u8>) -> Result<DecodedText> {
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..]) {