Crash in -[DTListItemHTMLElement _listPrefix] (nil NSFont) #661

Closed
js opened this Issue Oct 23, 2013 · 6 comments

Comments

Projects
None yet
2 participants

js commented Oct 23, 2013

I'm seeing a lot of crashes in our HockeyApp with this backtrace, unfortunately we don't capture enough info to hockey to know exactly what html causes this, but the backtrace is below.

This is with DTCoreText 1.6.6. The fallback font is also set with [DTCoreTextFontDescriptor setFallbackFontFamily:@"HelveticaNeue"]; (if that's related here).

Application Specific Information:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** setObjectForKey: object cannot be nil (key: NSFont)'

0   CoreFoundation                      0x3448e2a3 __exceptionPreprocess + 163
1   libobjc.A.dylib                     0x3c32497f _objc_exception_throw + 31
2   CoreFoundation                      0x343f0313 -[__NSDictionaryM setObject:forKey:] + 143
3   TheApp                                0x001ef7cd -[DTListItemHTMLElement _listPrefix] (DTListItemHTMLElement.m:153)
4   TheApp                                0x001efcc1 -[DTListItemHTMLElement attributedString] (DTListItemHTMLElement.m:281)
5   TheApp                                0x001e44f7 -[DTHTMLElement attributedString] (DTHTMLElement.m:419)
6   TheApp                                0x001e44f7 -[DTHTMLElement attributedString] (DTHTMLElement.m:419)
7   TheApp                                0x001e24d5 __54-[DTHTMLAttributedStringBuilder parser:didEndElement:]_block_invoke_2 (DTHTMLAttributedStringBuilder.m:769)
8   libdispatch.dylib                   0x3c73c11f _dispatch_call_block_and_release + 11
9   libdispatch.dylib                   0x3c73fecf _dispatch_queue_drain$VARIANT$mp + 143
10  libdispatch.dylib                   0x3c73fdc1 _dispatch_queue_invoke$VARIANT$mp + 41
11  libdispatch.dylib                   0x3c74091d _dispatch_root_queue_drain + 185
12  libdispatch.dylib                   0x3c740ac1 _dispatch_worker_thread2 + 85
13  libsystem_c.dylib                   0x3c770a11 _pthread_wqthread + 361
14  libsystem_c.dylib                   0x3c7708a4 _start_wqthread + 8
Collaborator

odrobnik commented Oct 23, 2013

This occurs if you have an attributed string that does not have a font on a list prefix.

Von meinem iPhone gesendet

Am 23.10.2013 um 14:11 schrieb Johan Sørensen notifications@github.com:

I'm seeing a lot of crashes in our HockeyApp with this backtrace, unfortunately we don't capture enough info to hockey to know exactly what html causes this, but the backtrace is below.

This is with DTCoreText 1.6.6. The fallback font is also set with [DTCoreTextFontDescriptor setFallbackFontFamily:@"HelveticaNeue"]; (if that's related here).

Application Specific Information:
* Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '* setObjectForKey: object cannot be nil (key: NSFont)'

0 CoreFoundation 0x3448e2a3 __exceptionPreprocess + 163
1 libobjc.A.dylib 0x3c32497f _objc_exception_throw + 31
2 CoreFoundation 0x343f0313 -[__NSDictionaryM setObject:forKey:] + 143
3 TheApp 0x001ef7cd -DTListItemHTMLElement _listPrefix
4 TheApp 0x001efcc1 -DTListItemHTMLElement attributedString
5 TheApp 0x001e44f7 -DTHTMLElement attributedString
6 TheApp 0x001e44f7 -DTHTMLElement attributedString
7 TheApp 0x001e24d5 __54-[DTHTMLAttributedStringBuilder parser:didEndElement:]_block_invoke_2 (DTHTMLAttributedStringBuilder.m:769)
8 libdispatch.dylib 0x3c73c11f _dispatch_call_block_and_release + 11
9 libdispatch.dylib 0x3c73fecf _dispatch_queue_drain$VARIANT$mp + 143
10 libdispatch.dylib 0x3c73fdc1 _dispatch_queue_invoke$VARIANT$mp + 41
11 libdispatch.dylib 0x3c74091d _dispatch_root_queue_drain + 185
12 libdispatch.dylib 0x3c740ac1 _dispatch_worker_thread2 + 85
13 libsystem_c.dylib 0x3c770a11 _pthread_wqthread + 361
14 libsystem_c.dylib 0x3c7708a4 _start_wqthread + 8

Reply to this email directly or view it on GitHub.

js commented Oct 23, 2013

Yeah thanks, it was parsed with the DTHTMLAttributedStringBuilder.

I was hoping it would fall back to the -fallbackFontFamily one, but it seems that's only when an invalid one is encountered…

Collaborator

odrobnik commented Oct 24, 2013

We need to have the HTML to see why there was no font at a range. That should never happen.

Best regards
Oliver Drobnik

@Cocoanetics on Twitter and App.net
www.cocoanetics.com

On 23.10.2013, at 21:57, Johan Sørensen notifications@github.com wrote:

Yeah thanks, it was parsed with the DTHTMLAttributedStringBuilder.

I was hoping it would fall back to the -fallbackFontFamily one, but it seems that's only when an invalid one is encountered…


Reply to this email directly or view it on GitHub.

js commented Nov 4, 2013

Was able to dig out one of the sources of text causing this crash, the app receives some wonderful craptastic HTML such as this occasionally:

    text = @"<b><ul><br /><li>asdf <br /><li>asdf<br /><li>asdf<br /><li>asdf<br /><li>asdf<br /><li>asdf<br /><li>asdf<br /><li>asdf<br /><li>asdf<br /><li>asdf<br /><li>asdf<br /></ul></b></li></li></li></li></li></li></li></li></li></li></li></li>";
    NSData *htmlData = [text dataUsingEncoding:NSUTF8StringEncoding];
    NSAttributedString *html = [[NSAttributedString alloc] initWithHTMLData:htmlData options:options documentAttributes:nil];

The options dict contains the following keys: NSTextSizeMultiplierDocumentOption (1.0),DTDefaultFontFamily (HelveticaNeue-Light),DTDefaultFontSize, DTDefaultStyleSheet (body { line-height: 120%; })

With the above I can reproduce the crash. Setting DTUseiOS6Attributes toYES gives the same result (except crashes in the if (___useiOS6Attributes) clause obviously).

js commented Nov 4, 2013

After extensive digging it appears the issue was with value given to + setFallbackFontFamily:, changing it from "HelveticaNeue" to "Helvetica Neue" (note the space) appears to make CTFontDescriptorCreateMatchingFontDescriptor find the correct font descriptor based on the _fallbackFontFamily.

I realize that might be obvious to anyone familiar with CTFontDescriptor, but perhaps that docs should mention what format this font string should be in?

Collaborator

odrobnik commented Nov 15, 2013

@js I'll add some info to the documentation and probably an assert to prevent setting a non-existing font family name.

@odrobnik odrobnik added a commit that referenced this issue Nov 15, 2013

@odrobnik odrobnik Added unit tests for #661 0a85f7a

odrobnik closed this Nov 15, 2013

@odrobnik odrobnik added a commit that referenced this issue Nov 15, 2013

@odrobnik odrobnik Added unit tests for #661 cbe06ad
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment