1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
//! The vendored k-way id-heap behind FlowCutter, driven through its own C++
//! self-test.
//!
//! Nothing here names a Rust item: the self-test is a C symbol in the archive
//! `build.rs` links, so this sits with the crate's other decomposition tests
//! rather than inside `flowcutter`, which it does not reach into.
use c_int;
// SAFETY: mirrors the declaration in `vendor/treedecomp/heap_selftest.cpp`, which is
// vendored here and built by `build.rs`; the self-test takes no arguments and
// returns a plain int, so there is nothing else to match.
unsafe extern "C"
/// Heap-overflow regression. The vendored FlowCutter k-way heap computed
/// child positions as `k*pos+1` in signed 32-bit int. A bag-adjacency graph
/// with more than ~5.4e8 elements makes `move_down` descend past
/// `INT_MAX/k`, the product overflows to a negative index, and
/// `heap[negative]` faults inside C++ — uncatchable from Rust. The fix makes
/// that arithmetic 64-bit.
///
/// This drives the C++ self-test directly: reproducing the real crash needs
/// tens of gigabytes and minutes of preprocessing, whereas the self-test
/// checks the same overflow boundary at zero memory cost, alongside general
/// heap correctness.