fix: kernel: move level parameter count and thm-is-prop checks for robustness#12734
fix: kernel: move level parameter count and thm-is-prop checks for robustness#12734
Conversation
The kernel would crash (access uninitialized memory) when `is_delta` succeeded for a constant whose supplied universe-level count did not match its declaration's level-parameter count. `unfold_definition_core` had the count check, so it returned `none_expr()` in that case. Call sites in `lazy_delta_reduction_step` unconditionally dereferenced that result, causing undefined behaviour (garbled error or SIGSEGV). Fix: add the level-parameter-count check to `is_delta` and remove the now- redundant check from `unfold_definition_core`. This establishes the invariant: if `is_delta` succeeds then `unfold_definition` will also succeed. Add a regression test from the fuzzer-discovered reproducer in #10577. Co-authored-by: nomeata <148037+nomeata@users.noreply.github.com>
Co-authored-by: nomeata <148037+nomeata@users.noreply.github.com>
|
@copilot please heed the commit conventions for PR title and description |
is_delta to prevent crash
|
@copilot also some unrelated changes snuck in |
Updated the PR description to follow the commit convention body format. The PR title also needs to be changed from "[WIP] Fix level parameter length check in is_delta" to |
is_delta to prevent crash…o .gitignore Co-authored-by: nomeata <148037+nomeata@users.noreply.github.com>
|
@copilot Don’t just change |
|
@copilot and fix the PR description to adhere to the commit convnetion (“This PR …”). You just overrode my changes. |
Co-authored-by: nomeata <148037+nomeata@users.noreply.github.com>
Reverted the |
Updated the PR description to follow the "This PR …" commit convention. |
|
Fun little experiment but we should really just make sure that - if (!checker.is_prop(type))
- throw theorem_type_is_not_prop(*this, v.get_name(), type);
check_constant_val(*this, v.to_constant_val(), checker);
+ if (!checker.is_prop(type))
+ throw theorem_type_is_not_prop(*this, v.get_name(), type); |
|
Yes, maybe worth doing both. I think there are more cases where type incorrect terms can flow to whnf or defeq, and even if we find and fix all of them the defense in depth here doesn't hurt. @copilot let's also move the thm-is-prop check further down, as suggested above, for more robustness. |
…or robustness Co-authored-by: nomeata <148037+nomeata@users.noreply.github.com>
Co-authored-by: nomeata <148037+nomeata@users.noreply.github.com>
... Done in 31630a8. Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
|
Mathlib CI status (docs):
|
|
Reference manual CI status:
|
This PR moves the universe-level-count check from
unfold_definition_coreintois_delta, establishing the invariant that ifis_deltasucceeds thenunfold_definitionalso succeeds. This prevents a crash (SIGSEGV or garbled error) that occurred when call sites inlazy_delta_reduction_stepunconditionally dereferenced the result ofunfold_definitioneven on a level-parameter-count mismatch.Additionally, moves the
is_propcheck for theorem types inadd_theoremto occur aftercheck_constant_val, so the type is verified to be well-formed beforeis_propevaluates it. This preventsis_propfrom being called on an ill-typed term when a malformed theorem declaration is supplied.Fixes #10577.