-
Notifications
You must be signed in to change notification settings - Fork 143
Prevent accessing unicode scalar element with incorrect index. #1214
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
Prevent accessing unicode scalar element with incorrect index. #1214
Conversation
41942f2
to
be12879
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for looking into this! I've got a couple comments to add on.
4f3fc97
to
6fe73e7
Compare
6fe73e7
to
5b39673
Compare
@swift-ci please test |
// Create a new string by mapping over the character helps | ||
// preventing crashes when handling substrings that contains | ||
// multibyte characters. | ||
self.map { String($0) }.joined() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this change necessary?
If so, what are the performance implications of this? Reading this naively it seems like it could be horribly slow. But I'm not familiar with how Swift implements strings and sub-strings internally. We should run a benchmark to make sure this isn't a hot spot.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I changed it back. Linux environments don't like constructing strings from substrings that contains multibyte characters and sometimes it results in crashes, but it's true that this has performance issues.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One request, one suggestion, and i'm also interested in @patshaughnessy's question.
b671925
to
1f92a91
Compare
@swift-ci please test |
1f92a91
to
435b602
Compare
435b602
to
45919d3
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approved with a comment about the tests
This change prevents a potential DocC crash by making sure that it does not access an array element using an index that is outside of the bonds of the array. `.index(after:` can crash in some cases if the passed index belongs to the last element of the collection. with this change we ensure that the passed index is not the last index. rdar://150760264
45919d3
to
4babd33
Compare
@swift-ci please test |
I added the requested changes, thx!
…lang#1214) This change prevents a potential DocC crash by making sure that it does not access an array element using an index that is outside of the bonds of the array. `.index(after:` can crash in some cases if the passed index belongs to the last element of the collection. with this change we ensure that the passed index is not the last index. rdar://150760264
#1219) This change prevents a potential DocC crash by making sure that it does not access an array element using an index that is outside of the bonds of the array. `.index(after:` can crash in some cases if the passed index belongs to the last element of the collection. with this change we ensure that the passed index is not the last index. rdar://150760264
Bug/issue #, if applicable: 150760264
Summary
This change prevents a potential DocC crash by making sure that it does not access an array element using an index that is outside of the bonds of the array.
.index(after:
can crash in some cases if the passed index belongs to the last element of the collection. with this change we ensure that the passed index is not the last index.Testing
Run unit tests in Linux using Swift 5.9.
Checklist
Make sure you check off the following items. If they cannot be completed, provide a reason.
./bin/test
script and it succeeded