Skip to content

[4.1][SourceKit] Add defensive guard for invalid offset #14869

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

Merged

Conversation

rintaro
Copy link
Member

@rintaro rintaro commented Feb 28, 2018

Cherry-pick of #14803 for swift-4.1-branch

Explanation: In some race conditions, SourceKit could receives invalid (too high) offset value in requests. This used cause undefined behavior in Lexer such as infinite loop in the worst case. This quick change adds a guard to prevent to propagate invalid offset values to the Lexer.

Scope: CursorInfo and RangeInfo requests for SourceKit.
Issue: rdar://problem/30346106
Risk: Very low. By this change, SourceKit guarantees to emit empty response (as expected) for cursor/range-info requests with invalid offset.
Testing: Added a regression test.
Reviewer: @akyrtzi

Invalid offset used to cause a inifinite loop in Lexer in some race
condition.

This is a quick fix until we fix underlying problem in SourceKit.
@rintaro
Copy link
Member Author

rintaro commented Feb 28, 2018

@swift-ci Please test

@rintaro rintaro merged commit 7ebaa8a into swiftlang:swift-4.1-branch Feb 28, 2018
@rintaro rintaro deleted the 4.1-sourcekit-offset-guard branch February 28, 2018 02:08
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

Successfully merging this pull request may close these issues.

1 participant