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
max_cliques() on a directed graph segfaults (C stack overflow) if any_multiple() was called first (igraph 2.3.3) #2748
Calling max_cliques() on a directed graph crashes R with Error: segfault from C stack overflow — but only if any_multiple() has been called on the graph beforehand. Either call alone is fine.
Additional observations:
max_cliques(g) alone works (returns 12 cliques, with the expected "Edge directions are ignored" warning). any_multiple(g) alone works.
Wrapping the call in suppressWarnings() does not prevent the crash.
The crash is specific to any_multiple() as the priming call: which_multiple(g), any_loop(g), or is_connected(g) before max_cliques(g) do not crash.
Undirected graphs are unaffected: max_cliques(as_undirected(g, mode = "collapse")) after any_multiple() is fine, suggesting the trigger is the directed-graph warning path in max_cliques().
In a sequence that doesn't crash, the "Edge directions are ignored for maximal clique calculations" warning is mis-attributed to has_multiple_impl (In has_multiple_impl(graph = graph) : Edge directions are ignored..., source cliques/maximal_cliques_template.h:221), which may point to stale condition-handler state left by any_multiple().
Found while testing the manynet package, but reproduces with igraph alone in a fresh session.
To reproduce
library(igraph) # 2.3.3
set.seed(1)
m <- matrix(rbinom(64, 1, .5), 8, 8); diag(m) <- 0
g <- graph_from_adjacency_matrix(m) # directed
invisible(any_multiple(g))
max_cliques(g)
#> Error: segfault from C stack overflow
This reprex appears to crash R.
See standard output and standard error for more details.
Standard output and error
*** caught segfault ***
address 0x111000006, cause 'memory not mapped'
Traceback:
1: max_cliques(g)
[remaining frames are reprex/rmarkdown/callr internals — omitted]
2. Smaller/faster deterministic case (n = 5 instead of 8)
Caught as an R-level condition (Error: segfault from C stack overflow) rather than a hard SIGSEGV, but same underlying cause — and it's exactly the error text from the issue title.
This reprex appears to crash R.
See standard output and standard error for more details.
Error: segfault from C stack overflow
double free or corruption (out)
Note the extra free(): invalid pointer / double free or corruption (out) glibc messages on these two — this isn't pure stack exhaustion, there's real heap corruption involved.
4. Not any_multiple()-specific either — is_simple() triggers it too
Same result (no crash) for count_multiple(g), any_loop(g), which_loop(g), count_loops(g), and is_connected(g) in place of which_multiple(g).
This narrows the trigger to functions that return a single "is this graph simple / does it have multi-edges" scalar (any_multiple, is_simple, has.multiple) rather than the per-edge variants (which_multiple, count_multiple) — those likely share one internal C code path, and the clique family's directed-graph handling is what stumbles into whatever state it leaves behind.
6. Not seed-specific — random directed graphs trigger it generally
Summary: the bug isn't limited to any_multiple() + max_cliques() specifically. It's any of {any_multiple, is_simple, has.multiple} (scalar "is-simple" checks) followed by any of {max_cliques, count_max_cliques, largest_cliques, clique_num} (the maximal-cliques family), and only on directed graphs. Per-edge variants (which_multiple, count_multiple) and loop-only checks (any_loop, which_loop, count_loops) don't trigger it, and undirected graphs are unaffected.
Root cause found: igraph_has_multiple()/is_simple() cache "no multi-edges" using out-edges only, which is true even when a reciprocal pair (a,b)/(b,a) exists; max_cliques() builds an undirected (IGRAPH_ALL-mode) adjacency list and trusted that cache to skip deduplication, so reciprocal pairs survived as duplicate entries and broke the clique search's recursion. Already fixed upstream in igraph/igraph e547b8007, not yet in a tagged release. Fix for rigraph: re-vendor src/vendor/cigraph from a commit at or after that fix.
Activity
Fixed any_multiple() bug from igraph in to_hypergraph() re igraph/rig…
maelle commentedon Aug 28, 2026
Posting some results from Claude
Additional reprexes for #2748
All run just now on this branch (
igraph 2.3.3.9033, R 4.5.2) viareprex::reprex().1. Original reprex, confirmed as-is
This reprex appears to crash R.
See standard output and standard error for more details.
Standard output and error
2. Smaller/faster deterministic case (n = 5 instead of 8)
Caught as an R-level condition (
Error: segfault from C stack overflow) rather than a hard SIGSEGV, but same underlying cause — and it's exactly the error text from the issue title.3. Not
max_cliques()-specific — the whole clique family is affectedThis reprex appears to crash R.
See standard output and standard error for more details.
Standard output and error
Also confirmed the same way for
largest_cliques(g)andclique_num(g)in place ofcount_max_cliques(g):This reprex appears to crash R.
See standard output and standard error for more details.
Error: segfault from C stack overflow free(): invalid pointerThis reprex appears to crash R.
See standard output and standard error for more details.
Note the extra
free(): invalid pointer/double free or corruption (out)glibc messages on these two — this isn't pure stack exhaustion, there's real heap corruption involved.4. Not
any_multiple()-specific either —is_simple()triggers it tooThis reprex appears to crash R.
See standard output and standard error for more details.
Standard output and error
has.multiple(g)reproduces it the same way;is.simple(g)is just the dotted alias ofis_simple().5. Controls that do not trigger it
Standard output and standard error
Same result (no crash) for
count_multiple(g),any_loop(g),which_loop(g),count_loops(g), andis_connected(g)in place ofwhich_multiple(g).This narrows the trigger to functions that return a single "is this graph simple / does it have multi-edges" scalar (
any_multiple,is_simple,has.multiple) rather than the per-edge variants (which_multiple,count_multiple) — those likely share one internal C code path, and the clique family's directed-graph handling is what stumbles into whatever state it leaves behind.6. Not seed-specific — random directed graphs trigger it generally
7. Control: undirected graphs never crash
Standard output and standard error
Summary: the bug isn't limited to
any_multiple()+max_cliques()specifically. It's any of{any_multiple, is_simple, has.multiple}(scalar "is-simple" checks) followed by any of{max_cliques, count_max_cliques, largest_cliques, clique_num}(the maximal-cliques family), and only on directed graphs. Per-edge variants (which_multiple,count_multiple) and loop-only checks (any_loop,which_loop,count_loops) don't trigger it, and undirected graphs are unaffected.maelle commentedon Aug 28, 2026
After more Claude use:
Root cause found:
igraph_has_multiple()/is_simple()cache "no multi-edges" using out-edges only, which istrueeven when a reciprocal pair(a,b)/(b,a)exists;max_cliques()builds an undirected (IGRAPH_ALL-mode) adjacency list and trusted that cache to skip deduplication, so reciprocal pairs survived as duplicate entries and broke the clique search's recursion. Already fixed upstream in igraph/igraphe547b8007, not yet in a tagged release. Fix for rigraph: re-vendorsrc/vendor/cigraphfrom a commit at or after that fix.krlmlr commentedon Sep 3, 2026
Let's hold off patching this, we'll have v1.0.x vendored soon.
szhorvat commentedon Oct 1, 2026
If this repro's with C core 1.x, can you please get a C reproducer and open an issue?