Skip to content

Commit

Permalink
Guard for overflow of the column offset when applying edits (#1952)
Browse files Browse the repository at this point in the history
  • Loading branch information
rwols authored Mar 23, 2022
1 parent 8972bae commit a3c6a61
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
4 changes: 2 additions & 2 deletions plugin/core/edit.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from .logging import debug
from .open import open_file
from .promise import Promise
from .protocol import TextEdit as LspTextEdit, Position
from .protocol import UINT_MAX, TextEdit as LspTextEdit, Position
from .typing import List, Dict, Any, Optional, Tuple
from functools import partial
import sublime
Expand Down Expand Up @@ -34,7 +34,7 @@ def parse_workspace_edit(workspace_edit: Dict[str, Any]) -> Dict[str, List[TextE


def parse_range(range: Position) -> Tuple[int, int]:
return range['line'], range['character']
return range['line'], min(UINT_MAX, range['character'])


def parse_text_edit(text_edit: LspTextEdit, version: int = None) -> TextEditTuple:
Expand Down
2 changes: 2 additions & 0 deletions plugin/core/protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import os
import sublime

INT_MAX = 2**31 - 1
UINT_MAX = INT_MAX

TextDocumentSyncKindNone = 0
TextDocumentSyncKindFull = 1
Expand Down
9 changes: 8 additions & 1 deletion tests/test_single_document.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
from setup import YieldPromise
import os
import sublime
import sys


try:
from typing import Generator, Optional, Iterable, Tuple, List
Expand Down Expand Up @@ -321,7 +323,12 @@ def test_rename(self) -> 'Generator':
'newText': 'bar'
},
{
'range': {'start': {'character': 0, 'line': 2}, 'end': {'character': 3, 'line': 2}},
'range':
{
'start': {'character': 0, 'line': 2},
# Check that lsp_apply_document_edit guards for overflow by using sys.maxsize + 1
'end': {'character': sys.maxsize + 1, 'line': 2}
},
'newText': 'bar'
}
]
Expand Down

0 comments on commit a3c6a61

Please sign in to comment.