Skip to content

fix(lsp): guard Locate against out-of-bounds ranges#196

Open
SAY-5 wants to merge 1 commit into
cloudwego:mainfrom
SAY-5:fix-locate-slice-bounds
Open

fix(lsp): guard Locate against out-of-bounds ranges#196
SAY-5 wants to merge 1 commit into
cloudwego:mainfrom
SAY-5:fix-locate-slice-bounds

Conversation

@SAY-5
Copy link
Copy Markdown

@SAY-5 SAY-5 commented May 24, 2026

What type of PR is this?

fix: A bug fix

Check the PR title.

  • This PR title match the format: <type>(optional scope): <description>
  • The description of this PR title is user-oriented and clear enough for others to understand.
  • Attach the PR updating the user documentation if the current PR requires user awareness at the usage level. User docs repo

(Optional) Translate the PR title into Chinese.

(Optional) More detailed description for this PR(en: English/zh: Chinese).

en: LSPClient.Locate indexes LineCounts by the LSP-provided line numbers and then slices text[start:end] without validating either. When an LSP server returns a stale or out-of-sync range (for example pylsp/jedi following imports into .venv), the line index can exceed len(LineCounts) or the offsets can be inverted, producing slice bounds out of range [13:6] and crashing the whole parse run. This adds bounds and ordering checks that return an error instead of panicking, matching the guard already present in the sibling Line method. A unit test covers the valid case and three out-of-bounds variants.
zh(optional):

(Optional) Which issue(s) this PR fixes:

Fixes #186

(optional) The PR that updates user documentation:

Signed-off-by: SAY-5 <say.apm35@gmail.com>
@CLAassistant
Copy link
Copy Markdown

CLAassistant commented May 24, 2026

CLA assistant check
All committers have signed the CLA.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

parse python panics in LSPClient.Locate (slice bounds out of range) when following imports into .venv

2 participants