Extremely large UTF-16 columns can keep an LSP worker busy

Aperta
#16,540 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
56/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva

Direzione di ricerca

Start with Lean.Data.Lsp.Utf16.lspPosToUtf8Pos and the Position documentation, then trace the shared LSP conversion entry points. Add regression coverage for huge columns, supplementary-plane characters, and positions beyond line endings; verify conversion time stays bounded by line length and the out-of-range position follows the documented policy.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Extremely large UTF-16 columns can keep an LSP worker busy

Summary

An LSP position request with a character value far beyond the source line length can make position conversion perform work proportional to the supplied value. The same conversion is shared by hover and other language features.

Steps to reproduce

Run lean --server, complete the LSP initialize handshake, and open a document containing def x : Nat := 1\n. Then send this hover request as a standard LSP frame:

{"jsonrpc":"2.0","id":2,"method":"textDocument/hover","params":{"textDocument":{"uri":"file:///tmp/Probe.lean"},"position":{"line":0,"character":1e100000}}}

For comparison, repeat with "character":100000000.

Expected behavior

The server should clamp the out-of-range column to the line end, consistent with the documented position semantics, or reject it promptly under a documented policy. Conversion time should be bounded by the line length.

Actual behavior

On the reviewed 4.37.0-pre build, the exponent-form request produced no hover response within four seconds while the file worker remained alive; the 100000000 control request returned. The relevant UTF-16 conversion source remains unchanged on master a2a6b48ad40269ecf6a27e7790c7e611e7bb55d4. The open #15695 concerns long-line column computation performance; it does not add a bound based on the requested column or clamp this out-of-range input.

Impact assessment

A client with access to the LSP process can consume worker CPU and delay requests for the affected document. The demonstrated impact is denial of service, not a process crash or code execution.

Root cause

Lean.Data.Lsp.Utf16.lspPosToUtf8Pos passes the client-supplied UTF-16 character value into a conversion loop without first limiting it to the available length of the line. The Position documentation describes the intended clamping behavior, but the conversion path does not enforce it.

Suggested fix

Clamp the requested UTF-16 column to the selected line's available UTF-16 length before converting it to a UTF-8/source position. Ensure work is bounded by the line's actual length and use checked or saturating conversions for large JSON integers. Add regression tests for very large columns, supplementary-plane characters, and positions beyond line endings across shared LSP conversion entry points.

Lingua principale
Lean
Stelle
10.3k
Fork
1.1k
Merge medio
19h 8m
PR unite (30g)
421

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di leanprover/lean4

Tutte le issue di leanprover/lean4

Issue simili

Altre issue su Backend & API Design

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.