wordpress-mobile / AztecEditor-iOS

A reusable native iOS visual HTML text editor component.
Mozilla Public License 2.0
615 stars 147 forks source link

Crash in LayoutManager.underlineGlyphRange #1386

Open Shiaulis opened 9 months ago

Shiaulis commented 9 months ago

Describe the bug Our users experience crashes that for now we are unable to reproduce. The stack trace of the crash is below. Is there any ways to make this method safer and do some safety checks for glyphRange?

Fatal Exception: NSRangeException
0  CoreFoundation                 0xec69c __exceptionPreprocess
1  libobjc.A.dylib                0x2bc80 objc_exception_throw
2  Foundation                     0x84118 -[NSAttributedString attributedSubstringFromRange:]
3  Pipedrive                      0x7f4da0 LayoutManager.underlineGlyphRange(_:underlineType:lineFragmentRect:lineFragmentGlyphRange:containerOrigin:) + 369 (LayoutManager.swift:369)
4  Pipedrive                      0x7f4f9c @objc LayoutManager.underlineGlyphRange(_:underlineType:lineFragmentRect:lineFragmentGlyphRange:containerOrigin:) (<compiler-generated>)
5  UIFoundation                   0x59168 -[NSLayoutManager(NSPrivate) _drawGlyphsForGlyphRange:atPoint:]
6  UIFoundation                   0x10b20 -[NSTextStorage coordinateReading:]
7  UIKitCore                      0x10be344 -[_UITextViewCanvasView drawTextInRect:]
8  UIKitCore                      0x10bdf50 -[_UITextCanvasView drawRect:]
9  UIKitCore                      0x15ac80 -[UIView(CALayerDelegate) drawLayer:inContext:]
10 UIKitCore                      0x10bf578 -[_UITextTiledLayer _drawInContext:offset:clip:]
11 UIKitCore                      0x10bf254 -[_UITileLayer drawInContext:]
12 QuartzCore                     0x68074 CABackingStoreUpdate_
13 QuartzCore                     0x67f6c invocation function for block in CA::Layer::display_()
14 QuartzCore                     0x67424 -[CALayer _display]
15 QuartzCore                     0x6673c CA::Layer::layout_and_display_if_needed(CA::Transaction*)
16 QuartzCore                     0x6cb60 CA::Context::commit_transaction(CA::Transaction*, double, double*)
17 QuartzCore                     0x65e3c CA::Transaction::commit()
18 UIKitCore                      0xe19970 __83-[UIApplication _createSnapshotContextForScene:withName:performLayoutWithSettings:]_block_invoke_4
19 UIKitCore                      0xe190a0 -[UIApplication _performWithUICACommitStateSnapshotting:]
20 UIKitCore                      0xe198e0 __83-[UIApplication _createSnapshotContextForScene:withName:performLayoutWithSettings:]_block_invoke_2
21 UIKitCore                      0x41a70 +[UIView(Animation) performWithoutAnimation:]
22 UIKitCore                      0xe196cc __83-[UIApplication _createSnapshotContextForScene:withName:performLayoutWithSettings:]_block_invoke
23 UIKitCore                      0x4bbc08 -[UIScene _applyOverrideSettings:forActions:]
24 UIKitCore                      0x1035f4c -[UIWindowScene _applySnapshotSettings:forActions:]
25 UIKitCore                      0xe195ac -[UIApplication _createSnapshotContextForScene:withName:performLayoutWithSettings:]
26 UIKitCore                      0xe1a794 __65-[UIApplication _performSnapshotsWithAction:forScene:completion:]_block_invoke_3
27 FrontBoardServices             0x6692c -[FBSSceneSnapshotAction _executeNextRequest]
28 FrontBoardServices             0x66948 -[FBSSceneSnapshotAction _executeNextRequest]
29 FrontBoardServices             0x663c0 -[FBSSceneSnapshotAction executeRequestsWithHandler:completionHandler:expirationHandler:]
30 UIKitCore                      0xe1a6e4 __65-[UIApplication _performSnapshotsWithAction:forScene:completion:]_block_invoke_2
31 UIKitCore                      0xe19f98 -[UIApplication _beginSnapshotSessionForScene:withSnapshotBlock:]
32 UIKitCore                      0xe1a594 __65-[UIApplication _performSnapshotsWithAction:forScene:completion:]_block_invoke
33 UIKitCore                      0x4bbb14 -[UIScene _enableOverrideSettingsForActions:]
34 UIKitCore                      0x4bbd2c -[UIScene _performSystemSnapshotWithActions:]
35 UIKitCore                      0xe1a410 -[UIApplication _performSnapshotsWithAction:forScene:completion:]
36 UIKitCore                      0x12dfd38 __98-[_UISceneSnapshotBSActionsHandler _respondToActions:forFBSScene:inUIScene:fromTransitionContext:]_block_invoke_3
37 UIKitCore                      0x12dfbbc __98-[_UISceneSnapshotBSActionsHandler _respondToActions:forFBSScene:inUIScene:fromTransitionContext:]_block_invoke_2
38 UIKitCore                      0x1375c8 -[UIScene _emitSceneSettingsUpdateResponseForCompletion:afterSceneUpdateWork:]
39 UIKitCore                      0x1372c4 -[UIScene scene:didUpdateWithDiff:transitionContext:completion:]
40 UIKitCore                      0x137104 -[UIApplicationSceneClientAgent scene:handleEvent:withCompletion:]
41 FrontBoardServices             0xe5b4 -[FBSScene updater:didUpdateSettings:withDiff:transitionContext:completion:]
42 FrontBoardServices             0xe300 __94-[FBSWorkspaceScenesClient _queue_updateScene:withSettings:diff:transitionContext:completion:]_block_invoke_2
43 FrontBoardServices             0xe19c -[FBSWorkspace _calloutQueue_executeCalloutFromSource:withBlock:]
44 FrontBoardServices             0xe0b8 __94-[FBSWorkspaceScenesClient _queue_updateScene:withSettings:diff:transitionContext:completion:]_block_invoke
45 libdispatch.dylib              0x4300 _dispatch_client_callout
46 libdispatch.dylib              0x7d48 _dispatch_block_invoke_direct
47 FrontBoardServices             0xa520 __FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK__
48 FrontBoardServices             0xa4a0 -[FBSMainRunLoopSerialQueue _targetQueue_performNextIfPossible]
49 FrontBoardServices             0xa378 -[FBSMainRunLoopSerialQueue _performNextFromRunLoopSource]
50 CoreFoundation                 0x3712c __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__
51 CoreFoundation                 0x363a8 __CFRunLoopDoSource0
52 CoreFoundation                 0x34b5c __CFRunLoopDoSources0
53 CoreFoundation                 0x33898 __CFRunLoopRun
54 CoreFoundation                 0x33478 CFRunLoopRunSpecific
55 GraphicsServices               0x34f8 GSEventRunModal
56 UIKitCore                      0x22c62c -[UIApplication _run]
57 UIKitCore                      0x22bc68 UIApplicationMain
58 Pipedrive                      0x84124 main + 19 (main.m:19)
59 ???                            0x1b4ab2dcc (Missing)

Smartphone (please complete the following information):

Shiaulis commented 9 months ago

I assume this was fixed by https://github.com/wordpress-mobile/AztecEditor-iOS/pull/1384