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
fix: nparams + idx unsigned wraparound in reduce_proj_core #13618
Reduce the issue to a minimal, self-contained, reproducible test case.
Test your test case against the latest nightly release.
Description
In src/kernel/type_checker.cpp:369-371, the bounds check in reduce_proj_core can be bypassed via unsigned integer wraparound:
unsigned nparams = mk_info.to_constructor_val().get_nparams();
if (nparams + idx < args.size()) // UNSIGNED WRAP: if idx near UINT_MAX, sum wraps to small valuereturn some_expr(args[nparams + idx]); // indexes wrong element
On 64-bit systems, unsigned is 32-bit (UINT_MAX = 2^32 - 1 ≈ 4.29 × 10^9). If idx is near UINT_MAX (crafted via a Proj or via corrupted metadata), nparams + idx wraps to a value < args.size(). The check passes but args[nparams + idx] reads the wrong element — kernel extracts the wrong struct field during projection reduction.
This is distinct from #12746/#13602 which are about the proj_idx truncation from size_t to unsigned (the narrowing conversion). This finding is about the subsequent arithmetic on the already-converted unsigned value.
nparams itself comes from declaration.h:300 (get_nparams()) which also lacks an is_small() guard (see #13616). Two issues compound: garbage nparams + unsigned-wrapping check.
Or use size_t arithmetic for the comparison to avoid the 32-bit wrap:
if (static_cast<size_t>(nparams) + idx < args.size())
Versions
Lean 4 (all versions)
All 64-bit platforms (LP64 data model: unsigned=32-bit)
Impact
Low. Requires idx near UINT_MAX, which is practically unreachable through normal term construction (terms would need >4 billion fields). However, in combination with the .olean corruption vectors documented in #13615, this becomes exploitable for reading out-of-bounds kernel objects.
Activity
proj_idxtruncation:size_t→unsigned#12746fix: stop truncating kernel counts and indices to 32 bits (leanprover…