macteo / Marklight

Markdown syntax highlighter for iOS
Other
638 stars 44 forks source link

Crash when editing text >4096 characters #20

Open tylerjames opened 6 years ago

tylerjames commented 6 years ago

I can reliably crash my app with the following error if I try to edit a textview containing >4096 characters:

int main(int, char **):17 - Uncaught exception: The index -4097 is invalid
2017-11-06 14:45:18.194 int main(int, char **):18 - Stack trace: (
    0   CoreFoundation                      0x000000010aadf1cb __exceptionPreprocess + 171
    1   libobjc.A.dylib                     0x000000010ba32f41 objc_exception_throw + 48
    2   CoreFoundation                      0x000000010ab53b95 +[NSException raise:format:] + 197
    3   Foundation                          0x0000000109d1665e -[NSString rangeOfComposedCharacterSequenceAtIndex:] + 73
    4   UIFoundation                        0x000000010f9cecd1 _NSFastFillAllGlyphHolesForCharacterRange + 604
    5   UIFoundation                        0x000000010fa0fbd9 -[NSLayoutManager glyphRangeForCharacterRange:actualCharacterRange:] + 64
    6   UIKit                               0x0000000107d8ddc8 __38-[UITextView _rectForScrollToVisible:]_block_invoke + 73
    7   UIFoundation                        0x000000010fa1322c -[NSLayoutManager(TextLocking) coordinateAccess:] + 55
    8   UIKit                               0x0000000107d8db69 -[UITextView _rectForScrollToVisible:] + 281
    9   UIKit                               0x0000000107d89f04 -[UITextView _updateContentSize] + 721
    10  CoreFoundation                      0x000000010aa7b07c __CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__ + 12
    11  CoreFoundation                      0x000000010aa7af7a _CFXRegistrationPost + 442
    12  CoreFoundation                      0x000000010aa7acc2 ___CFXNotificationPost_block_invoke + 50
    13  CoreFoundation                      0x000000010aa3ca32 -[_CFXNotificationRegistrar find:object:observer:enumerator:] + 1826
    14  CoreFoundation                      0x000000010aa3bbac _CFXNotificationPost + 652
    15  Foundation                          0x0000000109cbc842 -[NSNotificationCenter postNotificationName:object:userInfo:] + 66
    16  UIKit                               0x0000000107da76cf __64-[_UITextContainerView _setFrameOrBounds:oldRect:settingAction:]_block_invoke.60 + 212
    17  UIKit                               0x0000000107da754c -[_UITextContainerView _setFrameOrBounds:oldRect:settingAction:] + 607
    18  UIKit                               0x0000000107da7a46 -[_UITextContainerView setFrame:] + 225
    19  UIKit                               0x0000000107da7cf0 -[_UITextContainerView setConstrainedFrameSize:] + 542
    20  UIFoundation                        0x000000010f9d14c7 -[NSLayoutManager(NSPrivate) _resizeTextViewForTextContainer:] + 745
    21  UIFoundation                        0x000000010f9d109d -[NSLayoutManager(NSPrivate) _recalculateUsageForTextContainerAtIndex:] + 2232
    22  UIFoundation                        0x000000010fa0801e _enableTextViewResizing + 228
    23  UIFoundation                        0x000000010fa0c556 -[NSLayoutManager textStorage:edited:range:changeInLength:invalidatedRange:] + 584
    24  UIFoundation                        0x000000010fa0c5aa -[NSLayoutManager processEditingForTextStorage:edited:range:changeInLength:invalidatedRange:] + 47
    25  UIFoundation                        0x000000010fa37cb3 -[NSTextStorage _notifyEdited:range:changeInLength:invalidatedRange:] + 168
    26  UIFoundation                        0x000000010fa377f2 -[NSTextStorage processEditing] + 372
    27  Marklight                           0x00000001042fc9d7 _T09Marklight0A11TextStorageC14processEditingyyF + 407
    28  Marklight                           0x00000001042fcb44 _T09Marklight0A11TextStorageC14processEditingyyFTo + 36
    29  UIFoundation                        0x000000010fa3743b -[NSTextStorage endEditing] + 83
    30  UIKit                               0x0000000107df43a9 -[UITextInputController _insertText:fromKeyboard:] + 525
    31  UIKit                               0x0000000107df5e20 -[UITextInputController deleteBackward] + 230
    32  UIKit                               0x0000000107d8d5f7 -[UITextView deleteBackward] + 37
    33  UIKit                               0x00000001073db56d -[UIKeyboardImpl deleteBackwardAndNotify:] + 134
    34  UIKit                               0x00000001073d6c63 -[UIKeyboardImpl performKeyboardOutput:] + 637
    35  UIKit                               0x00000001073d6155 __55-[UIKeyboardImpl handleKeyboardInput:executionContext:]_block_invoke_2 + 270
    36  UIKit                               0x0000000107e3c2f5 -[UIKeyboardTaskQueue continueExecutionOnMainThread] + 374
    37  Foundation                          0x0000000109d1c948 __NSThreadPerformPerform + 334
    38  CoreFoundation                      0x000000010aa822b1 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
    39  CoreFoundation                      0x000000010ab21d31 __CFRunLoopDoSource0 + 81
    40  CoreFoundation                      0x000000010aa66c19 __CFRunLoopDoSources0 + 185
    41  CoreFoundation                      0x000000010aa661ff __CFRunLoopRun + 1279
    42  CoreFoundation                      0x000000010aa65a89 CFRunLoopRunSpecific + 409
    43  GraphicsServices                    0x00000001104f09c6 GSEventRunModal + 62
    44  UIKit                               0x00000001070d7d30 UIApplicationMain + 159
    45  Chime Spaces                        0x0000000102d79e42 main + 66
    46  libdyld.dylib                       0x000000010dcc0d81 start + 1
)

It seems to have a problem processing longer text, the -4097 is suspicious, it makes it look like there is an overflow or something.

In order to achieve this I copied a few paragraphs of text, pasted them into Sublime until I got to 4096 or so, and then pasted them into my text view in the simulator. After pasting things will work fine, but then after typing some more characters or possibly backspacing or dismissing the keyboard the crash will happen. It seems to occur during the processEditing() method

ivancantarino commented 6 years ago

have you found a solution for this?

tylerjames commented 6 years ago

Unfortunately not. I ended up switching over to this: https://github.com/raspu/Highlightr

It's been pretty decent so far, but honestly it's a somewhat small part of my app so I really haven't stress tested it much. The only reason I found out about the previous bug was that one of my users pasted in a good sized chunk of text.

Good luck

ivancantarino commented 6 years ago

I'm looking for a markdown highlighter on-the-fly, similar to the Apollo iOS app or iA Writer, which highlights markdown syntax as the user types in. Marklight seems to be exactly what I need, but it seems to have small issues as well.

Does Highlightr supports markdown?

tylerjames commented 6 years ago

Marklight is nice because it’s written in Swift. However that Highlightr library uses a JavaScript engine for syntax highlighting. It should work for your purposes though and it comes with many themes On Tue, May 15, 2018 at 8:16 AM Ivan-Cantarino notifications@github.com wrote:

I'm looking for a markdown highlighter on-the-fly, similar to the Apollo iOS app or iA Writer, which highlights markdown syntax as the user types in. Marklight seems to be exactly what I need, but it seems to have small issues as well.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/macteo/Marklight/issues/20#issuecomment-389145347, or mute the thread https://github.com/notifications/unsubscribe-auth/ABFfjTpGWg8GM7R1cZRmskq6Fl7o43gkks5tyscCgaJpZM4QT0go .

ivancantarino commented 6 years ago

I'm testing Highlightr right now and in their Sample project it supports markdown syntax highlight on the fly, so it should solve my issues.

Thanks for pointing it out ;)