]> granicus.if.org Git - graphviz/commitdiff
pathplan: fix integer overflow with > 46341 nodes
authorMatthew Fernandez <matthew.fernandez@gmail.com>
Sun, 25 Dec 2022 20:39:16 +0000 (12:39 -0800)
committerMatthew Fernandez <matthew.fernandez@gmail.com>
Sun, 8 Jan 2023 20:52:31 +0000 (12:52 -0800)
After this change, a ASan+UBSan build of Graphviz can process the #1999 example
without crashing. Graphs with >46341 (⌈√INT_MAX⌉) nodes no longer cause an
integer overflow.

Gitlab: fixes #1999
Reported-by: Lockywolf
CHANGELOG.md
lib/pathplan/visibility.c

index 5e7a67ad2738a7db074d77a0b73d37e72f6fecc0..30479deecbfd4db5582d83d1c78736e3f7a02824 100644 (file)
@@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
 
 - The Autotools build system no longer errors when attempting libANN discovery
   during cross-compilation. This was a regression in Graphviz 7.0.6. #2335
+- Graphs with more than 46341 (⌈√INT_MAX⌉) nodes no longer crash `twopi`. #1999
 
 ## [7.0.6] – 2023-01-06
 
index 94abb67dd4f40f584ae40ab206d0f0398dd2d4bf..52d21bf2ddf9476da3b185457bcd4a6150621167 100644 (file)
@@ -8,7 +8,7 @@
  * Contributors: Details at https://graphviz.org
  *************************************************************************/
 
-
+#include <assert.h>
 #include <pathplan/vis.h>
 #include <stdbool.h>
 #include <stdlib.h>
@@ -33,8 +33,9 @@ static array2 allocArray(int V, int extra)
     array2 arr;
     COORD *p;
 
+    assert(V >= 0);
     arr = malloc((V + extra) * sizeof(COORD *));
-    p = calloc(V * V, sizeof(COORD));
+    p = calloc((size_t)V * (size_t)V, sizeof(COORD));
     for (i = 0; i < V; i++) {
        arr[i] = p;
        p += V;