Mercurial > octave-nkf
diff libinterp/dldfcn/__voronoi__.cc @ 18077:ac74b0c4c564 stable
avoid overflow when passing problem dimensions to qhull with --enable-64
* __delaunayn__.cc, __voronoi__.cc, convhulln.cc
(octave_qhull_dims_ok): New function. Use it to avoid overflowing
the range of integer values used in Qhull when Octave uses 64-bit
integer indexing.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Tue, 03 Dec 2013 21:39:39 -0500 |
parents | 175b392e91fe |
children | 65554f5847ac 446c46af4b42 |
line wrap: on
line diff
--- a/libinterp/dldfcn/__voronoi__.cc Wed Dec 04 08:41:22 2013 -0800 +++ b/libinterp/dldfcn/__voronoi__.cc Tue Dec 03 21:39:39 2013 -0500 @@ -59,6 +59,23 @@ gnulib::fclose (f); } +static bool +octave_qhull_dims_ok (octave_idx_type dim, octave_idx_type n, const char *who) +{ + if (sizeof (octave_idx_type) > sizeof (int)) + { + int maxval = std::numeric_limits<int>::max (); + + if (dim > maxval || n > maxval) + { + error ("%s: dimension too large for Qhull", who); + return false; + } + } + + return true; +} + DEFUN_DLD (__voronoi__, args, , "-*- texinfo -*-\n\ @deftypefn {Loadable Function} {@var{C}, @var{F} =} __voronoi__ (@var{caller}, @var{pts})\n\ @@ -86,6 +103,9 @@ const octave_idx_type dim = points.columns (); const octave_idx_type num_points = points.rows (); + if (! octave_qhull_dims_ok (dim, num_points, "__voronoi__")) + return retval; + points = points.transpose (); std::string options;