Overly large array allocation may panic with "integer overflow"

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

Direzione di ricerca

Start with the Array.replicate and ByteArray.emptyWithCapacity reproductions in the issue, then trace their runtime allocation paths and relevant tests. Reproduce the reported overflow with Lean 4.35.0 and compare interpreted and compiled behavior. Done means oversized requests are accepted or rejected gracefully without an uncaught runtime panic.

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

Descrizione

bug P-low
Prerequisites
  • [ x] Check that your issue is not already filed:
    https://github.com/leanprover/lean4/issues
  • [ x] Reduce the issue to a minimal, self-contained, reproducible test case.
    Avoid dependencies to Mathlib or Batteries.
  • Test your test case against the latest nightly release, for example on
    https://live.lean-lang.org/#project=lean-nightly
    (You can also use the settings there to switch to “Lean nightly”)
    locally reproduced with nightly
  • When reporting a perceived soundness bug: Does it affect lake check --paranoid?
    If in doubt, please reach out on [email protected] for responsible disclosure.
Description

Minimal repro:

-- Repro.lean   (lean-toolchain: leanprover/lean4:v4.35.0)
  def main : IO Unit := do
    let n : Nat := 2^61   -- 2^61 * sizeof(void*) overflows size_t on 64-bit
    IO.println s!"allocating Array of {n} elements"
    let a := Array.replicate n (0 : Nat)
    IO.println s!"size = {a.size}"
  $ lean --run Repro.lean
  INTERNAL PANIC: integer overflow in runtime computation      (exit 1)

Variants:

  ┌───────────────────────────────────────────────┬─────────────────────────────────────────────────────────┐
  │                     Case                      │                Interpreted and compiled                 │
  ├───────────────────────────────────────────────┼─────────────────────────────────────────────────────────┤
  │ Array.replicate (2^60)                        │ INTERNAL PANIC: out of memory                           │
  ├───────────────────────────────────────────────┼─────────────────────────────────────────────────────────┤
  │ Array.replicate (2^61)                        │ INTERNAL PANIC: integer overflow in runtime computation │
  ├───────────────────────────────────────────────┼─────────────────────────────────────────────────────────┤
  │ ByteArray.emptyWithCapacity (2^63) and (2^64) │ out of memory                                           │
  ├───────────────────────────────────────────────┼─────────────────────────────────────────────────────────┤
  │ Array.replicate (2^61) inside try … catch     │ still aborts; not catchable                             │
  └───────────────────────────────────────────────┴─────────────────────────────────────────────────────────┘

Expected behavior: [Clear and concise description of what you expect to happen]

Accept the program or a graceful rejection instead of a panic.

Actual behavior: [Clear and concise description of what actually happens]

Panic

Versions

4.35.0, reproduced on Linux and Mac.

Additional Information

[Additional information, configuration or data that might be necessary to reproduce the issue]

Impact

Add 👍 to issues you consider important. If others are impacted by this issue, please ask them to add 👍 to it.

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.