[GRASS-SVN] r68083 - grass/trunk/raster/r.in.lidar

svn_grass at osgeo.org svn_grass at osgeo.org
Sat Mar 19 13:03:04 PDT 2016


Author: wenzeslaus
Date: 2016-03-19 13:03:04 -0700 (Sat, 19 Mar 2016)
New Revision: 68083

Modified:
   grass/trunk/raster/r.in.lidar/main.c
   grass/trunk/raster/r.in.lidar/point_binning.c
   grass/trunk/raster/r.in.lidar/support.c
Log:
r.in.lidar: cast to size_t before multiplying rows and cols

Otherwise it segfaults with number of cells larger
than max of signed int.


Modified: grass/trunk/raster/r.in.lidar/main.c
===================================================================
--- grass/trunk/raster/r.in.lidar/main.c	2016-03-19 12:27:49 UTC (rev 68082)
+++ grass/trunk/raster/r.in.lidar/main.c	2016-03-19 20:03:04 UTC (rev 68083)
@@ -551,7 +551,7 @@
         if (base_array) {
             G_debug(2, "filling base raster array");
             for (row = 0; row < rows; row++) {
-                Rast_get_row(base_raster, base_array + (row * cols * Rast_cell_size(base_raster_data_type)), row, base_raster_data_type);
+                Rast_get_row(base_raster, base_array + ((size_t) row * cols * Rast_cell_size(base_raster_data_type)), row, base_raster_data_type);
             }
         }
 

Modified: grass/trunk/raster/r.in.lidar/point_binning.c
===================================================================
--- grass/trunk/raster/r.in.lidar/point_binning.c	2016-03-19 12:27:49 UTC (rev 68082)
+++ grass/trunk/raster/r.in.lidar/point_binning.c	2016-03-19 20:03:04 UTC (rev 68083)
@@ -89,7 +89,7 @@
 
     ptr =
         G_incr_void_ptr(ptr,
-                        ((row * cols) + col) * Rast_cell_size(CELL_TYPE));
+                        (((size_t) row * cols) + col) * Rast_cell_size(CELL_TYPE));
 
     /* first node */
     if (Rast_is_null_value(ptr, CELL_TYPE)) {
@@ -234,6 +234,7 @@
     if (sizeof(size_t) < 8) {
         double dsize = rows * (cols + 1);
 
+        /* TODO: the comparison with double may fail */
         if (dsize != (size_t) rows * (cols + 1))
             return FALSE;
     }
@@ -380,8 +381,8 @@
     void *ptr = raster_row;
 
     for (col = 0; col < cols; col++) {
-        offset = (row * cols + col) * Rast_cell_size(rtype);
-        n_offset = (row * cols + col) * Rast_cell_size(CELL_TYPE);
+        offset = ((size_t) row * cols + col) * Rast_cell_size(rtype);
+        n_offset = ((size_t) row * cols + col) * Rast_cell_size(CELL_TYPE);
         n = Rast_get_c_value(n_array + n_offset, CELL_TYPE);
         sum = Rast_get_d_value(sum_array + offset, rtype);
         sumsq = Rast_get_d_value(sumsq_array + offset, rtype);
@@ -430,7 +431,7 @@
     void *ptr = raster_row;
 
     for (col = 0; col < cols; col++) {
-        n_offset = (row * cols + col) * Rast_cell_size(CELL_TYPE);
+        n_offset = ((size_t) row * cols + col) * Rast_cell_size(CELL_TYPE);
         if (Rast_is_null_value(index_array + n_offset, CELL_TYPE))      /* no points in cell */
             Rast_set_null_value(ptr, 1, rtype);
         else {                  /* one or more points in cell */
@@ -486,7 +487,7 @@
     void *ptr = raster_row;
 
     for (col = 0; col < cols; col++) {
-        n_offset = (row * cols + col) * Rast_cell_size(CELL_TYPE);
+        n_offset = ((size_t) row * cols + col) * Rast_cell_size(CELL_TYPE);
         if (Rast_is_null_value(index_array + n_offset, CELL_TYPE))      /* no points in cell */
             Rast_set_null_value(ptr, 1, rtype);
         else {
@@ -541,7 +542,7 @@
     void *ptr = raster_row;
 
     for (col = 0; col < cols; col++) {
-        n_offset = (row * cols + col) * Rast_cell_size(CELL_TYPE);
+        n_offset = ((size_t) row * cols + col) * Rast_cell_size(CELL_TYPE);
         if (Rast_is_null_value(index_array + n_offset, CELL_TYPE))      /* no points in cell */
             Rast_set_null_value(ptr, 1, rtype);
         else {
@@ -597,7 +598,7 @@
     void *ptr = raster_row;
 
     for (col = 0; col < cols; col++) {
-        n_offset = (row * cols + col) * Rast_cell_size(CELL_TYPE);
+        n_offset = ((size_t) row * cols + col) * Rast_cell_size(CELL_TYPE);
         if (Rast_is_null_value(index_array + n_offset, CELL_TYPE))      /* no points in cell */
             Rast_set_null_value(ptr, 1, rtype);
         else {
@@ -662,32 +663,32 @@
     case METHOD_N:             /* n is a straight copy */
         Rast_raster_cpy(raster_row,
                         point_binning->n_array +
-                        (row * cols * Rast_cell_size(CELL_TYPE)), cols,
+                        ((size_t) row * cols * Rast_cell_size(CELL_TYPE)), cols,
                         CELL_TYPE);
         break;
 
     case METHOD_MIN:
         Rast_raster_cpy(raster_row,
                         point_binning->min_array +
-                        (row * cols * Rast_cell_size(rtype)), cols, rtype);
+                        ((size_t) row * cols * Rast_cell_size(rtype)), cols, rtype);
         break;
 
     case METHOD_MAX:
         Rast_raster_cpy(raster_row,
                         point_binning->max_array +
-                        (row * cols * Rast_cell_size(rtype)), cols, rtype);
+                        ((size_t) row * cols * Rast_cell_size(rtype)), cols, rtype);
         break;
 
     case METHOD_SUM:
         Rast_raster_cpy(raster_row,
                         point_binning->sum_array +
-                        (row * cols * Rast_cell_size(rtype)), cols, rtype);
+                        ((size_t) row * cols * Rast_cell_size(rtype)), cols, rtype);
         break;
 
     case METHOD_RANGE:         /* (max-min) */
         ptr = raster_row;
         for (col = 0; col < cols; col++) {
-            size_t offset = (row * cols + col) * Rast_cell_size(rtype);
+            size_t offset = ((size_t) row * cols + col) * Rast_cell_size(rtype);
             double min =
                 Rast_get_d_value(point_binning->min_array + offset, rtype);
             double max =
@@ -700,8 +701,8 @@
     case METHOD_MEAN:          /* (sum / n) */
         ptr = raster_row;
         for (col = 0; col < cols; col++) {
-            size_t offset = (row * cols + col) * Rast_cell_size(rtype);
-            size_t n_offset = (row * cols + col) * Rast_cell_size(CELL_TYPE);
+            size_t offset = ((size_t) row * cols + col) * Rast_cell_size(rtype);
+            size_t n_offset = ((size_t) row * cols + col) * Rast_cell_size(CELL_TYPE);
             int n = Rast_get_c_value(point_binning->n_array + n_offset,
                                      CELL_TYPE);
             double sum =
@@ -747,8 +748,8 @@
     }
     if (point_binning->bin_coordinates) {
         for (col = 0; col < cols; col++) {
-            size_t offset = (row * cols + col) * Rast_cell_size(rtype);
-            size_t n_offset = (row * cols + col) * Rast_cell_size(CELL_TYPE);
+            size_t offset = ((size_t) row * cols + col) * Rast_cell_size(rtype);
+            size_t n_offset = ((size_t) row * cols + col) * Rast_cell_size(CELL_TYPE);
             int n = Rast_get_c_value(point_binning->n_array + n_offset,
                                      CELL_TYPE);
 

Modified: grass/trunk/raster/r.in.lidar/support.c
===================================================================
--- grass/trunk/raster/r.in.lidar/support.c	2016-03-19 12:27:49 UTC (rev 68082)
+++ grass/trunk/raster/r.in.lidar/support.c	2016-03-19 20:03:04 UTC (rev 68083)
@@ -136,7 +136,7 @@
     void *ptr = array;
     ptr =
         G_incr_void_ptr(ptr,
-                        ((arr_row * cols) +
+                        (((size_t) arr_row * cols) +
                          arr_col) * Rast_cell_size(rtype));
     if (Rast_is_null_value(ptr, rtype))
         return 0;



More information about the grass-commit mailing list