Skip to content

Commit 8fbddc5

Browse files
committed
Perform a range check before accessing the high byte
1 parent 58ca9f2 commit 8fbddc5

1 file changed

Lines changed: 6 additions & 5 deletions

File tree

ycmd/completers/language_server/language_server_protocol.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -823,11 +823,12 @@ def UTF16CodeUnitsToCodepoints( line_value, code_unit_offset ):
823823
# is one-past-the-end of the string in unicode codepoints
824824
return len( line_value ) + 1
825825

826-
hi_byte_at_offset = value_as_utf16_bytes[byte_offset_utf16 + 1]
827-
if 0xdc <= hi_byte_at_offset <= 0xdf:
828-
# If we are in the middle of a surrogate pair, then advance the offset
829-
# further to skip the pair
830-
code_unit_offset += 1
826+
if byte_offset_utf16 < len( value_as_utf16_bytes ):
827+
hi_byte_at_offset = value_as_utf16_bytes[ byte_offset_utf16 + 1 ]
828+
if 0xdc <= hi_byte_at_offset <= 0xdf:
829+
# If we are in the middle of a surrogate pair, then advance the offset
830+
# further to skip the pair
831+
code_unit_offset += 1
831832

832833
bytes_included = value_as_utf16_bytes[ : code_unit_offset * 2 ]
833834
return len( bytes_included.decode( 'utf-16-le' ) )

0 commit comments

Comments
 (0)