`paragraphRange` signature does not specify the returning type could be nullable, leading to unexpected crashes
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 35/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Stale
- Tech stack
- swift
- Domain
- mobile-dev
Research direction
Start in Aztec/Classes/Extensions/NSAttributedString+ParagraphRange.swift at paragraphRange(for: NSTextAttachment), especially the ranges(forAttachment:) call. Search its callers to understand how the return value is used, then verify the attachment-not-found path no longer causes an unexpected crash and that affected callers handle the result appropriately.
Written by the indexing model from the issue text.
Description
We've seen some crashes in WooCommerce for iOS coming from our AztecEditor wrapper. This seems to come from the underlying usage of paragraphRange, since assumes that the attachment passed into the method is the string, force-unwrapping the first result of the attachments array:
func paragraphRange(for attachment: NSTextAttachment) -> NSRange {
// We assume the attachment IS in the string. This method should not be called otherwise.
let attachmentRange = ranges(forAttachment: attachment).first!
return paragraphRange(for: attachmentRange)
}
This leads to unexpected crashes when the method is not used as intended, since its signature does not specify that the result could be nil. Ideally we should change the returning type to NSRange?, or handle the existence of nil values internally.
- Dominant language
- Swift
- Stars
- 669
- Forks
- 153
- Avg merge
- 11h 27m
- Merged PRs (30d)
- 4
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from wordpress-mobile/AztecEditor-iOS
-
Bug
Difficulty 3/5 1-2 days Newbie friendliness 45/100
wordpress-mobile/AztecEditor-iOS#1417 · 1 comment ·
-
Difficulty 4/5 3-5 days Newbie friendliness 45/100
wordpress-mobile/AztecEditor-iOS#1411 ·
-
wordpress-mobile/AztecEditor-iOS#1401 · 2 comments · 1 assignee ·
-
Difficulty 3/5 1-2 days Newbie friendliness 35/100
wordpress-mobile/AztecEditor-iOS#1399 ·
-
Difficulty 3/5 1-2 days Newbie friendliness 35/100
wordpress-mobile/AztecEditor-iOS#1398 · 1 comment · 1 reaction ·
All issues in wordpress-mobile/AztecEditor-iOS
Similar issues
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
-
type: docs
Difficulty 1/5 Under an hour Newbie friendliness 95/100
googleapis/google-cloud-swift#971 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
bitcoindevkit/bdk-ffi#1125 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
mozilla-mobile/firefox-ios#35743 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
manaflow-ai/cmux#13417 ·