Inverted didChange ranges can amplify document contents

Aperta
#16,541 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
49/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva

Direzione di ricerca

Start with the LSP range replacement path shared by watchdog and file-worker handling, then inspect the end-to-end harness lsp_textsync_e2e.py and its document setup and change flow. Reproduce the repeated inverted textDocument/didChange edit and request semantic tokens. Done means an end-to-end regression test confirms invalid edits do not grow the document or increase later request work.

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

Descrizione

Inverted didChange ranges can amplify document contents

Summary

An inverted LSP textDocument/didChange range is applied without validating that start precedes end. Repeating a small edit with such a range expands the in-memory document and increases later language-feature work.

Steps to reproduce

Run lean --server, initialize it, and open a document containing eight lines of def x : Nat := 1. Send the following notification four times, incrementing the document version for each notification, then request textDocument/semanticTokens/full:

{"jsonrpc":"2.0","method":"textDocument/didChange","params":{"textDocument":{"uri":"file:///tmp/Probe.lean","version":2},"contentChanges":[{"range":{"start":{"line":0,"character":1000000},"end":{"line":0,"character":0}},"text":""}]}}

Repeat as four separate notifications, increasing version each time.

The tested end-to-end harness is lsp_textsync_e2e.py; it performs framing, document setup, repeated edits, and token requests.

Expected behavior

The server should reject the inverted range or leave the document unchanged. Repeated invalid edits must not increase document size or the work required by later requests.

Actual behavior

On the reviewed 4.37.0-pre build, the semantic-token response grew from 40 integers at baseline to 80 after one edit and 640 after four edits. The worker remained alive in the tested cases. Relevant server range-edit code was unchanged between the reviewed commit and master a2a6b48ad40269ecf6a27e7790c7e611e7bb55d4.

Impact assessment

A client that can send changes for an open document can cause document and follow-on parsing work to grow from a small request. The demonstrated impact is CPU and memory resource exhaustion; the tested cases did not crash the worker.

Root cause

The range replacement path converts the supplied endpoints and performs text slicing without validating start <= end. Watchdog and file-worker handling share the affected range replacement behavior.

Suggested fix

Validate each range before slicing or replacing text. Reject inverted ranges and apply a consistent documented policy to positions beyond the document. Use overflow-safe checks for the resulting document size and enforce reasonable per-document and per-notification change limits before committing edits. Add an end-to-end regression test that repeats the inverted edit and verifies no document growth.

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.