A Spotlight bug affecting all recent macOS: the LG error
There’s a bug in Spotlight that can prevent it from indexing any of the contents of susceptible text files. This has been present since macOS 13 Ventura if not before, and is still present in Tahoe 26.0.1. I didn’t discover this myself, though: it was reported to me by Jürgen, to whom full credit is due. It’s also one of the strangest bugs I’ve come across, and all depends on two letters.
Demonstration
To demonstrate this bug, all you need is a single UTF-8 plain text file, created by TextEdit or any other app capable of saving plain text. Start the text with the two characters L
and G
, both in capitals. Then add one or more distinctive words, such asLG syzygy
Save that file to a folder that you know is indexed and searched by Spotlight, then a few seconds later try searching for the word syzygy in its contents. Extend this as much as you want, maybe appending the whole of one of Charles Dickens’ novels, but no matter how you search for its contents, that file will never be found. If you want to get more serious, use that text file in my Spotlight test app SpotTest, and it will also be unable to find that file.
This only works with plain text files, not Rich Text, PDF or HTML. It’s also sensitive to those two letters. Set one of them in lowercase, preface them with a space, or substitute a different letter, and the contents of that file will then be indexed correctly and searchable as normal.
Affected macOS
I have tested this in virtual machines going back as far as macOS 13 Ventura, and it’s present in them all. If you have access to an earlier version of macOS, I’d be interested to know whether it affects that as well.
Cause
The two UTF-8 characters concerned, 4c 47
, don’t appear to be anything special that could be misinterpreted.
Although it’s not easy to distinguish failure to index from search errors, saving a test file does result in repeated reports of an error that could cause Spotlight to fail when trying to index the file, for example the log entries30.946740 mdwrite Decoding error: Error Domain=NSCocoaErrorDomain Code=4864 UserInfo={NSDebugDescription=[private]} for [private]
30.951004 mds Decoding error: Error Domain=NSCocoaErrorDomain Code=4864 UserInfo={NSDebugDescription=[private]} for [private]
Error code 4864 is NSCoderReadCorruptError, implying that the presence of those two characters at the start of a text file may be triggering a bug in RichText.mdimporter, the importer module shipped in macOS that’s responsible for indexing plain text files.
My current hypothesis is therefore that text files starting with the characters LG
are failing to have their contents indexed correctly because of a bug in RichText.mdimporter.
History
This isn’t the first bug in the RichText.mdimporter. In macOS Catalina 10.15.6, the same mdimporter (then build 319.60.100) introduced a bug that broke indexing of Rich Text (RTF) files. That was perpetuated through early releases of Big Sur until it was finally fixed in RichText.mdimporter build 326.11 in Big Sur 11.3.
Because text files starting with the characters LG
are exceedingly unusual, this bug appears to have been left in RichText.mdimporter for a great deal longer.
I will be reporting this to Apple in Feedback later this month. Please feel free to file your own Feedback if you can spare the time.
Summary
- In macOS 13 to 26, plain text files starting with the characters
LG
cannot be searched for their contents. - This appears to be the result of a longstanding bug in RichText.mdimporter in macOS.
- If those characters are altered, or prefixed by a space, indexing and search behave normally.
I’m very grateful to Jürgen for drawing this to my attention.