]> granicus.if.org Git - graphviz/commitdiff
twopi: fix crash with > 46341 nodes
authorMatthew Fernandez <matthew.fernandez@gmail.com>
Sun, 25 Dec 2022 20:25:49 +0000 (12:25 -0800)
committerMatthew Fernandez <matthew.fernandez@gmail.com>
Sun, 8 Jan 2023 20:49:13 +0000 (12:49 -0800)
UBSan revealed the graph attached to #1999 was triggering an integer overflow in
this multiplication, later on causing a crash in `twopi`. Any number of nodes
≥⌈√INT_MAX⌉ exceeds INT_MAX during multiplication. This fix still does not
enable the graph to be processed in a reasonable amount of time, and it still
crashes later after several hours due to another integer overflow.

Gitlab: #1999

lib/twopigen/circle.c

index 6046a5ded6e8d5985cd70729297179b1f89d55b7..78faa5f19229ebd36b61d0beffdf83b98bf36195 100644 (file)
@@ -8,6 +8,7 @@
  * Contributors: Details at https://graphviz.org
  *************************************************************************/
 
+#include    <assert.h>
 #include    <cgraph/alloc.h>
 #include    <twopigen/circle.h>
 #include    <ctype.h>
@@ -70,7 +71,8 @@ static bool isLeaf(Agraph_t * g, Agnode_t * n)
 static void initLayout(Agraph_t * g)
 {
     int nnodes = agnnodes(g);
-    uint64_t INF = (uint64_t)(nnodes * nnodes);
+    assert(nnodes >= 0);
+    uint64_t INF = (uint64_t)nnodes * (uint64_t)nnodes;
 
     for (Agnode_t *n = agfstnode(g); n; n = agnxtnode(g, n)) {
        SCENTER(n) = INF;