Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash in String+UTF16.swift - unescapeUTF16() #35

Closed
Frederiks96 opened this issue Jan 20, 2019 · 2 comments
Closed

Crash in String+UTF16.swift - unescapeUTF16() #35

Frederiks96 opened this issue Jan 20, 2019 · 2 comments

Comments

@Frederiks96
Copy link

I have experienced a crash in the unescapeUTF16 method in String+UTF16.swift. The markdown that led to the crash can be found here: https://github.com/apple/swift-evolution/blob/master/proposals/0240-ordered-collection-diffing.md

The crash was found on the line let endIndex = index(self.startIndex, offsetBy: $0 + 4) in the following code snippet:

stride(from: 0, to: count, by: 4).forEach {
    let startIndex = index(self.startIndex, offsetBy: $0)
    let endIndex = index(self.startIndex, offsetBy: $0 + 4)
    let hex4 = String(self[startIndex..<endIndex])
    if let utf16 = UInt16(hex4, radix: 16) {
        utf16Array.append(utf16)
    }
}
@DavidLari
Copy link

On a fork of this project called Haring, we fixed this issue by adding the following line to the beginning of the function. It stops the crash, but perhaps there's a better fix.

guard count >= 4 else { return nil }

bmoliveira added a commit that referenced this issue Jan 21, 2019
--
Changes:
 - Fixed a bug parsing code elements with UTFDecoding see Issue #35
 - Improved readability of code regex and limited until 3 ```
 - Refactored Example project to support internet markdowns
@bmoliveira bmoliveira mentioned this issue Jan 21, 2019
@bmoliveira
Copy link
Owner

This crash should not be happening anymore.

But the code Element parser is not working 100% according to the Github parser if the language is specified it will appear on the final view and it shouldn't.

Check out #37 for more information.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants