Skip to content

leanchecker --from-export panics (Expected a ConstantInfo.inductInfo) instead of erroring on an inductive whose all field names a non-inductive #16698

Done

Description

@MariusVanDerWijden

Description

leanchecker --from-export aborts the process with an internal panic when an export's inductive declaration has an all field that lists a name which is not an inductive type (e.g. a constructor). It should reject the malformed export with an error, as it does for other malformed inputs, rather than panic.

The panic is in Lean.Kernel.Environment.Replay.replayConstant, which maps the inductive's all list through ConstantInfo.inductiveVal! (a partial accessor) without checking that each referenced constant is actually an inductInfo.

Steps to reproduce

Save the following as bad.txt (lean4export NDJSON, format 3.1.0):

{"meta":{"exporter":{"name":"lean4export","version":"3.1.0"},"format":{"version":"3.1.0"},"lean":{"githash":"0000000000000000000000000000000000000000","version":"4.38.0"}}}
{"in":1,"str":{"pre":0,"str":"I"}}
{"ie":0,"sort":0}
{"in":2,"str":{"pre":1,"str":"mk"}}
{"const":{"name":1,"us":[]},"ie":1}
{"inductive":{"ctors":[{"cidx":0,"induct":1,"isUnsafe":false,"levelParams":[],"name":2,"numFields":0,"numParams":0,"type":1}],"recs":[],"types":[{"all":[2],"ctors":[2],"isRec":false,"isReflexive":false,"isUnsafe":false,"levelParams":[],"name":1,"numIndices":0,"numNested":0,"numParams":0,"type":0}]}}

Here the inductive type is I (name 1), but its types[0].all lists [2] — name 2 is the constructor mk, not an inductive.

Run:

leanchecker --from-export bad.txt

Actual behaviour

PANIC at Lean.ConstantInfo.inductiveVal! Lean.Declaration:520:9: Expected a `ConstantInfo.inductInfo`.
backtrace:
  ... lean_panic_fn_borrowed
  ... List.mapM.loop spec at Lean.Kernel.Environment.Replay.replayConstant
  ... Lean.Kernel.Environment.Replay.replayConstants
  ... Lean.Kernel.Environment.replay
  ... checkExport

Exit code 1, with an internal-panic abort.

Expected behaviour

A malformed export should be reported as an error (non-zero exit with a diagnostic), not an internal panic. For comparison, several independent kernel reimplementations reject this same input cleanly with a normal error.

Versions

Reproduced on:

  • 4.38.0-nightly-2026-11-22 (commit 7e2fc6a7267dbad33478f18096b4c1c7f1a8746e)
  • 4.35.0 (release)

Notes

This looks like the same replay-robustness area as the recent hardening in #16138 and #16279: replayConstant trusts the all field and calls the partial ConstantInfo.inductiveVal! on each entry. A check that each name in all is an inductInfo (throwing an IO.userError otherwise) would turn this into a normal rejection.

Activity

  1. added
    bug
    on Nov 23, 2026
  2. nomeata commented on Nov 23, 2026

    @nomeata
    Collaborator

    Is this related to #16675?

  3. MariusVanDerWijden commented on Nov 24, 2026

    @MariusVanDerWijden
    Author

    Kinda, same area but #16675 doesn't cover it.
    Here the map key and ci.name agree, the bad name is inside all, so the new n==ci.name check passes and replayConstant still calls newConstants[n]! / inductiveVal! unchecked

    (src/Lean/Replay.lean:105–111 on current master).

  4. MariusVanDerWijden commented on Nov 24, 2026

    @MariusVanDerWijden
    Author

    Following up on my reply above: this is closest to #16688, which is about the same .inductInfo branch of replayConstant trusting all. There is also a second panic in the same place. If all names a constant that the export doesn't declare, the [n]! lookup panics first:

    {"meta":{"exporter":{"name":"lean4export","version":"3.1.0"},"format":{"version":"3.1.0"},"lean":{"githash":"0000000000000000000000000000000000000000","version":"4.38.0"}}}
    {"in":1,"str":{"pre":0,"str":"I"}}
    {"ie":0,"sort":0}
    {"in":2,"str":{"pre":1,"str":"mk"}}
    {"const":{"name":1,"us":[]},"ie":1}
    {"in":3,"str":{"pre":0,"str":"J"}}
    {"inductive":{"ctors":[{"cidx":0,"induct":1,"isUnsafe":false,"levelParams":[],"name":2,"numFields":0,"numParams":0,"type":1}],"recs":[],"types":[{"all":[3],"ctors":[2],"isRec":false,"isReflexive":false,"isUnsafe":false,"levelParams":[],"name":1,"numIndices":0,"numNested":0,"numParams":0,"type":0}]}}
    PANIC at Std.DHashMap.Internal.AssocList.get! Std.Data.DHashMap.Internal.AssocList.Basic:163:11: key is not present in hash table
    PANIC at Lean.ConstantInfo.inductiveVal! Lean.Declaration:520:9: Expected a `ConstantInfo.inductInfo`.
    

    Both variants still reproduce on nightly-2026-11-24 (59cbe22). A fix would check that every name in info.all is present in newConstants and is an .inductInfo, and that every name in each member's ctors is present (line 111 looks those up with newConstants[n]! too) (and, per #16688, that all contains the entry's own name), and throw a normal error otherwise.

    (Also found while fuzzing the export parser: an Expr.bvar index of 2^20 − 1 or more, for example {"ie":0,"bvar":1048575}, ends leanchecker --from-export with INTERNAL PANIC: too many bound variables (lean_expr_mk_data), even when nothing uses the expression. The 20-bit limit itself is intended (see #16279), but the parser could reject such an index with an ordinary error.)

  5. added a commit that references this issue on Nov 24, 2026
    e6e2521
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions