3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2026-06-10 10:57:15 +00:00
z3/src
Copilot a5495b78fa
Avoid invalidated column-cell references in LP pivot paths (#9783)
MSVC ASan reports showed a container-overflow in LP tableau pivoting,
reproducible from both examples and solver tests (issue #9781). The
failure came from reading a `column_cell` through a reference after
pivoting removed that entry from the backing column.

- **Root cause**
- `pivot_column_tableau` and the analogous Diophantine elimination loop
both held `auto& c = column.back()` across a call
(`pivot_row_to_row_given_cell`) that immediately removes that very cell
from the column via `remove_element`.
- After the mutation, the subsequent read `c.var()` used for bookkeeping
observed invalid memory.

- **Change**
- Record the affected row in the bookkeeping set (`m_touched_rows` /
`m_changed_rows`) by reading `c.var()` **before** the pivot call, while
the back cell is still valid.
- Make `static_matrix::pivot_row_to_row_given_cell` return `void`
instead of `bool`. Its result (`!rowii.empty()`) was always `true`: both
callers keep the matrix at full row rank (the tableau basis columns form
an identity submatrix; the Diophantine `m_l_matrix` stays invertible),
so an elementary row operation can never empty a row. The dead `if
(!...) return false;` early-exit in `pivot_column_tableau` is removed
and replaced with a `SASSERT(!rowii.empty())` documenting the invariant.

- **Affected code paths**
- `src/math/lp/static_matrix.h`, `src/math/lp/static_matrix.cpp`,
`src/math/lp/static_matrix_def.h`
  - `src/math/lp/lp_core_solver_base_def.h`
  - `src/math/lp/dioph_eq.cpp`

- **Behavioral impact**
  - No algorithmic change to pivoting.
- Removes the stale-reference hazard in the loops that repeatedly
eliminate entries from a column.

```c++
while (column.size() > 1) {
    auto& c = column.back();
    SASSERT(c.var() != piv_row_index);
    if (m_touched_rows != nullptr)
        m_touched_rows->insert(c.var());
    m_A.pivot_row_to_row_given_cell(piv_row_index, c, j);
}
```

- **Verification**
- Reproduced the exact issue #9781 failure on a local ASan build
(`container-overflow` in `pivot_column_tableau`) using the pre-fix code,
and confirmed it is gone with this change.
- The 4 reported tests pass clean under ASan: `c_example`,
`cpp_example`, `test-z3 get_implied_equalities`, `test-z3 quant_solve`.
  - Full `test-z3 /a` suite: 89 passed, 0 failed, 0 ASan errors.

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: Nikolaj Bjorner <nbjorner@microsoft.com>
Co-authored-by: Lev Nachmanson <levnach@hotmail.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-06-09 07:36:05 -07:00
..
ackermannization Fix off-by-one vulnerabilities: use range-based for on goals; cache loop bound 2026-02-19 22:37:22 +00:00
api Fixes necessary to compile z3 included in clang-tidy via FetchContents. (#9768) 2026-06-08 19:44:01 -07:00
ast Fix right-side can_add indexing in sls_seq_plugin edit-distance repair (#9773) 2026-06-08 19:36:14 -07:00
cmd_context refactor solver to include settable stats 2026-06-07 14:17:38 -07:00
math Avoid invalidated column-cell references in LP pivot paths (#9783) 2026-06-09 07:36:05 -07:00
model disable test in tptp, move to native lambdas 2026-06-02 10:38:51 -07:00
muz spacer: enable model completion in arith qe_project (#9776) 2026-06-08 19:35:49 -07:00
nlsat making try-for tactic exception resilient on cancelation 2026-04-26 15:58:24 -07:00
opt Fixes necessary to compile z3 included in clang-tidy via FetchContents. (#9768) 2026-06-08 19:44:01 -07:00
params prepare for lambda unfolding in ho-matcher and selectively enable ho matching 2026-05-22 13:25:01 -07:00
parsers Add SMT-LIB choice support via array OP_CHOICE and instantiate choice axioms in array solvers (#9649) 2026-05-27 10:05:06 -07:00
qe Cleanup thanks to Copilot (#9709) 2026-06-04 10:46:33 -07:00
sat refactor solver to include settable stats 2026-06-07 14:17:38 -07:00
shell Fixes necessary to compile z3 included in clang-tidy via FetchContents. (#9768) 2026-06-08 19:44:01 -07:00
smt refactor solver to include settable stats 2026-06-07 14:17:38 -07:00
solver refactor solver to include settable stats 2026-06-07 14:17:38 -07:00
tactic refactor solver to include settable stats 2026-06-07 14:17:38 -07:00
test Fix right-side can_add indexing in sls_seq_plugin edit-distance repair (#9773) 2026-06-08 19:36:14 -07:00
util Handle SIGXCPU like a regular timeout (#9697) 2026-06-03 07:26:38 -07:00
CMakeLists.txt git bindings v1.0 2026-02-18 21:02:25 -08:00