Ad

Our DNA is written in Swift
Jump

Radar: Enumerating NSAttributedString Attributes on Multiple Threads causes EXC_BAD_ACCESS

This bug has been causing me grief for the last month or so, as it was hard to pin down without a concrete use case that can reliably reproduce it. GitHub user brovador finally was able to narrow it down to be able to repro it every time.

There appears to be a bug in NSAttributedString that causes an EXC_BAD_ACCESS if you try to enumerate certain attributes over a longer range on two separate attributed strings from two background threads.

I filed it as rdar://15139980 and on Open Radar. The sample is the DTCoreTextExceptionExample on our Radar Samples GitHub repo.

Summary

If you enumerate attributes on two different NSAttributedString instances on two background threads an EXC_BAD_ACCESS is caused by -attribute:atIndex:effectiveRange: method.

Steps to Reproduce

Launch the provided sample app.

Expected Results

There should be no crash.

Actual Results

The app crashes showing two crashed threads at DTCoreTextLayoutFrame.m:949.

I’m enclosing a screen shot of the crash.

If you enable the the synchronization at line 939 then the crash no longer occurs.

Version

7.0 (11A465)

Notes

This bug was also present in iOS 6.

Configuration

iOS 7 Simulator

NSAttributedStrings enumeration crash


Categories: Bug Reports

5 Comments »

  1. Where is the guarantee in the docs that NSAttributedString is thread-safe? This sounds like NSNumberFormatter and NSDateFormatter which, up until iOS7 were not thread-safe, but were often assumed to be.

  2. I always found working with Attributed Strings to be an incredibly long winded and tedious process, so I made a Mac App that creates all the code for you. https://itunes.apple.com/us/app/attributed-string-creator/id730928349?mt=12