swiftlang / sourcekit-lsp

Language Server Protocol implementation for Swift and C-based languages
Apache License 2.0
3.33k stars 280 forks source link

Fix a crash when trying to apply in edit that has out of line positions #1798

Closed ahoppen closed 4 weeks ago

ahoppen commented 1 month ago

LineTable.replace did not actually validate that the edit is in range. This could cause crashes of SourceKit-LSP if the editor is sending us bogus edits. Validate the position, like we do in all the other position conversions and log a fault if the edit is out-of-range.

While fixing this, I found a couple more places where line table accesses were not properly guarded. I migrated them to safe alternatives as well.

rdar://138962353

ahoppen commented 1 month ago

@swift-ci Please test

plemarquand commented 4 weeks ago

@swift-ci Please test