An oversized LSP Content-Length can terminate the server with an OOM panic

Aperta
#16,539 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
1-2 giorni
Idoneità per principianti
58/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva

Direzione di ricerca

Start with src/Lean/Data/Lsp/Communication.lean, where the issue says Content-Length is parsed and passed to the JSON stream reader. Trace that read path and check how the length is represented and validated before allocation. Done means oversized and unrepresentable lengths are rejected safely; the issue also calls for boundary and truncated-body tests.

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

Descrizione

An oversized LSP Content-Length can terminate the server with an OOM panic

Summary

The LSP frame reader accepts an attacker-controlled Content-Length without a protocol-level maximum before reading the body. A short header declaring an enormous body causes the server to panic with out-of-memory and exit.

Steps to reproduce

On a POSIX shell, pipe this header with no body to the reviewed lean executable:

printf 'Content-Length: 1000000000000000\r\n\r\n' | lean --server
Expected behavior

The server should reject an oversized frame as a protocol error and close the input cleanly. It should not attempt an effectively unbounded allocation or terminate with an OOM panic.

Actual behavior

On the reviewed 4.37.0-pre build, this 36-byte header triggered INTERNAL PANIC: out of memory and a non-zero exit in approximately 0.13 seconds. The same input path is present in master a2a6b48ad40269ecf6a27e7790c7e611e7bb55d4; relevant source files were unchanged since the reviewed commit.

Impact assessment

A peer that can write frames to lean --server can terminate the affected language-server process, interrupting editor services handled by that process. This demonstrates a process-availability failure; no data disclosure or code execution was observed. Exploitation requires access to the process input, such as through an exposed language-service proxy.

Root cause

src/Lean/Data/Lsp/Communication.lean parses the declared length and passes it to the JSON stream reader without enforcing a protocol-level maximum. The subsequent read path attempts to consume the declared amount and panics on resource exhaustion.

Suggested fix

Validate Content-Length before allocation or body reads. Reject values above a documented configurable limit and values that cannot be safely represented by the platform size type, using checked conversions and arithmetic. Return a protocol error where possible and close only the offending client connection. Add tests for oversized values, integer boundaries, and truncated bodies.

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.