You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
leanchecker --from-export panics (Expected a ConstantInfo.inductInfo) instead of erroring on an inductive whose all field names a non-inductive #16698
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):
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.
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.
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
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:
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.)
Activity
nomeata commentedon Nov 23, 2026
Is this related to #16675?
MariusVanDerWijden commentedon Nov 24, 2026
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).
MariusVanDerWijden commentedon Nov 24, 2026
Following up on my reply above: this is closest to #16688, which is about the same
.inductInfobranch ofreplayConstanttrustingall. There is also a second panic in the same place. Ifallnames 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}]}}Both variants still reproduce on nightly-2026-11-24 (59cbe22). A fix would check that every name in
info.allis present innewConstantsand is an.inductInfo, and that every name in each member'sctorsis present (line 111 looks those up withnewConstants[n]!too) (and, per #16688, thatallcontains the entry's own name), and throw a normal error otherwise.(Also found while fuzzing the export parser: an
Expr.bvarindex of 2^20 − 1 or more, for example{"ie":0,"bvar":1048575}, endsleanchecker --from-exportwithINTERNAL 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.)fix: reject malformed inductive entries in `Kernel.Environment.replay` (