# Fix crash when opening files with a BOM on macOS \(\#40419\) · gitcafe/zed

[View on GitCafe](https://git.cafe/gitcafe/zed/commit/b26491f5700d1a86ba1d9321eb99c65a8d4cb668)

Repository: [gitcafe/zed](https://git.cafe/gitcafe/zed)

Visibility: public

Requested revision: b26491f5700d1a86ba1d9321eb99c65a8d4cb668

Requested commit: b26491f5700d1a86ba1d9321eb99c65a8d4cb668

Commit: b26491f5700d1a86ba1d9321eb99c65a8d4cb668

Tree: f5696603053609bc37c33ee13a021e6fdedc8821

Author: Cole Miller

Committer: GitHub

## Message

```
Fix crash when opening files with a BOM on macOS (#40419)

Closes #40359

We were segfaulting when opening a UTF-8 file starting with a byte order
mark due to a mismatch in our UTF-16 indexing calculations caused by
Core Foundations `replace_str` stripping the BOM internally. This PR
fixes the crash by replacing one of our manual calculations by calling
the Core Foundations API to get the length of a string.

Release Notes:

- Fixed a crash on macOS when opening a file that starts with a UTF-8
byte order mark (BOM).

Co-authored-by: HactarCE <6060305+HactarCE@users.noreply.github.com>
```

## Parents

- [738dcd0c3a6007c2131adf9f7d81c89c4bbf631e](https://git.cafe/gitcafe/zed/commit/738dcd0c3a6007c2131adf9f7d81c89c4bbf631e?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zed/tree/b26491f5700d1a86ba1d9321eb99c65a8d4cb668?format=markdown)
