LSP invalid-params responses can spend seconds formatting a short JSON exponent

Aperta
#16,538 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
45/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Attiva

Direzione di ricerca

Start with the exponent parsing and number formatting paths in src/Lean/Data/Json/Parser.lean and src/Lean/Data/Json/Basic.lean, then trace how malformed request parameters are serialized in src/Lean/Server/Requests.lean and src/Lean/Server/Watchdog.lean. Add an LSP regression test using the supplied request with 1e100000; done means the error response is prompt and bounded.

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

Descrizione

LSP invalid-params responses can spend seconds formatting a short JSON exponent

Summary

On Lean 4 master, a malformed LSP request can force expensive formatting of a large JSON exponent when the server serializes the invalid parameters into its error response. The input token is only eight bytes, but 1e100000 is accepted at the current exponent limit and expands to a 100,001-digit natural number.

Steps to reproduce

Run lean --server, complete the LSP initialize handshake, then send the following JSON-RPC request as a normal LSP frame. Set Content-Length to the UTF-8 byte length of the JSON body.

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

The server should reject the malformed parameters promptly and return a bounded error response. Error formatting should not materialize or print a 100,001-digit integer.

Actual behavior

On the reviewed 4.37.0-pre build, the request takes approximately 7–8 seconds to produce an invalid-parameters response of about 100 KB. Relevant source files were unchanged between the reviewed commit 427023483cddad04689cf959e3e23589811c867a and master a2a6b48ad40269ecf6a27e7790c7e611e7bb55d4.

Impact assessment

A client with access to the LSP process can repeatedly occupy a file worker for several seconds and cause large error responses to be built and sent. Concurrent requests can increase CPU and response-buffer/transport memory use. This demonstrates denial of service under the stated access condition; it does not demonstrate information disclosure or code execution.

Root cause

The JSON parser accepts the exponent at its 100000 limit and eagerly expands it into a large natural number. When request parameter validation fails, the LSP error path serializes the original parameters, triggering costly decimal formatting. Relevant paths include src/Lean/Data/Json/Parser.lean, src/Lean/Data/Json/Basic.lean, and the invalid-parameter response path in src/Lean/Server/Requests.lean / src/Lean/Server/Watchdog.lean.

This is related to #13987, which concerns panics for exponents beyond the parser's limit. This report concerns the expensive accepted boundary value when it is echoed by LSP error handling.

Suggested fix

Avoid eagerly expanding positive exponents when the value only needs to be echoed, for example by preserving the coefficient/exponent representation and emitting bounded scientific notation. Independently bound the size and cost of invalid-parameter details before formatting or sending them. Add an LSP regression test with a malformed request containing 1e100000 and assert that the error response remains bounded and prompt.

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.