From: Matthew Fernandez Date: Sun, 8 Nov 2020 22:56:27 +0000 (-0800) Subject: fix: anticipate no non-normal edges when computing direction with concentrate X-Git-Tag: 2.46.0~12^2~2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=84e468e775e1d1b293624f1c8e70c226eb4a6e41;p=graphviz fix: anticipate no non-normal edges when computing direction with concentrate With concentrate enabled (`concentrate=true`), the direction of edges is analyzed in lib/dotgen/conc.c. The loops in `samedir()` did not anticipate that they may not find a single non-normal edge before hitting the end of an edge chain. This change removes this assumption. Fixes #167, #1771. --- diff --git a/CHANGELOG.md b/CHANGELOG.md index ca70fc6e9..db845ee95 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -67,6 +67,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - sfdp craches #236 - fdp segmentation fault with GK=0 #1290 - fdp crash #1865 +- Graphviz always crash with this simple dot file #167 +- Seg fault in dot #1771 ## [2.44.1] - 2020-06-29 diff --git a/lib/dotgen/conc.c b/lib/dotgen/conc.c index 136a15744..e2be813b1 100644 --- a/lib/dotgen/conc.c +++ b/lib/dotgen/conc.c @@ -28,8 +28,12 @@ static boolean samedir(edge_t * e, edge_t * f) { edge_t *e0, *f0; - for (e0 = e; ED_edge_type(e0) != NORMAL; e0 = ED_to_orig(e0)); - for (f0 = f; ED_edge_type(f0) != NORMAL; f0 = ED_to_orig(f0)); + for (e0 = e; e0 != NULL && ED_edge_type(e0) != NORMAL; e0 = ED_to_orig(e0)); + if (e0 == NULL) + return FALSE; + for (f0 = f; f0 != NULL && ED_edge_type(f0) != NORMAL; f0 = ED_to_orig(f0)); + if (f0 == NULL) + return FALSE; if (ED_conc_opp_flag(e0)) return FALSE; if (ED_conc_opp_flag(f0)) diff --git a/rtest/167.dot b/rtest/167.dot new file mode 100644 index 000000000..46a5d8f6b --- /dev/null +++ b/rtest/167.dot @@ -0,0 +1,8 @@ +digraph G { + concentrate=true; + a -> 4 -> b + a -> b + a -> b + b -> a +} + diff --git a/rtest/test_regression.py b/rtest/test_regression.py index 1daf11944..62c9f211f 100644 --- a/rtest/test_regression.py +++ b/rtest/test_regression.py @@ -103,6 +103,22 @@ def test_165_3(): assert any(r'hello \\\" world' in l for l in ldraw), \ 'unexpected ldraw contents' +def test_167(): + ''' + using concentrate=true should not result in a segfault + https://gitlab.com/graphviz/graphviz/-/issues/167 + ''' + + # locate our associated test case in this directory + input = os.path.join(os.path.dirname(__file__), '167.dot') + assert os.path.exists(input), 'unexpectedly missing test case' + + # process this with dot + ret = subprocess.call(['dot', '-Tpdf', '-o', os.devnull, input]) + + # Graphviz should not have caused a segfault + assert ret != -signal.SIGSEGV, 'Graphviz segfaulted' + def test_793(): ''' Graphviz should not crash when using VRML output with a non-writable current