Skip to content

Kernel accesses uninitialized memory #10577

@TwoFX

Description

@TwoFX

Prerequisites

Please put an X between the brackets as you perform the following steps:

Description

Here is some code (discovered via fuzzing)

import Lean
def name_0 : Lean.Name := .anonymous
def level_0 : Lean.Level := .zero
def name_1 : Lean.Name := .str name_0 "false_of_true_eq_false"
def expr_0 : Lean.Expr := .lit (.natVal 0)
def expr_1 : Lean.Expr := .const name_1 [level_0]
def name_2 : Lean.Name := .str name_0 "Eq"
def expr_18 : Lean.Expr := .const name_2 [level_0]
def expr_8 : Lean.Expr := .letE `d (.bvar 0) (.bvar 0) (.bvar 0) false
def expr_10 : Lean.Expr := .const name_1 []
def expr_11 : Lean.Expr := .app expr_10 expr_8
def expr_13 : Lean.Expr := .app expr_18 expr_0
def expr_16 : Lean.Expr := .letE `c expr_11 (.bvar 0) (.bvar 0) false
def expr_27 : Lean.Expr := .app (.app expr_13 expr_1) expr_0
def expr_30 : Lean.Expr := .letE `b (.bvar 0) expr_27 expr_16 false
def expr_36 : Lean.Expr := .letE `a (.sort level_0) expr_10 expr_30 false
def decl_0 : Lean.Declaration :=
  .thmDecl {
    name := `foo42
    levelParams := []
    type := expr_36
    value := expr_10
  }
run_meta Lean.addDecl decl_0

It realiably crashes live.lean-lang.org. On my computer, it prints (kernel) unknown constant '__expr_for_default_constructor__'. In both cases, the problem appears to be the following line, where unfold_definition returns none_expr, but the code tries to extract the expression:

s_n = whnf_core(*unfold_definition(s_n), false, true);

It seems unlikely that this can be developed into an exploit.

Expected behavior: No crash on live.lean-lang.org

Actual behavior: Crashes live.lean-lang.org

Versions

Lean 4.25.0-nightly-2025-09-26

Impact

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    P-mediumWe may work on this issue if we find the timebugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions