comparison libinterp/dldfcn/convhulln.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
comparison
equal deleted inserted replaced
18075:24759ac2b8cb 18077:ac74b0c4c564
51 51
52 static void 52 static void
53 close_fcn (FILE *f) 53 close_fcn (FILE *f)
54 { 54 {
55 gnulib::fclose (f); 55 gnulib::fclose (f);
56 }
57
58 static bool
59 octave_qhull_dims_ok (octave_idx_type dim, octave_idx_type n, const char *who)
60 {
61 if (sizeof (octave_idx_type) > sizeof (int))
62 {
63 int maxval = std::numeric_limits<int>::max ();
64
65 if (dim > maxval || n > maxval)
66 {
67 error ("%s: dimension too large for Qhull", who);
68 return false;
69 }
70 }
71
72 return true;
56 } 73 }
57 74
58 DEFUN_DLD (convhulln, args, nargout, 75 DEFUN_DLD (convhulln, args, nargout,
59 "-*- texinfo -*-\n\ 76 "-*- texinfo -*-\n\
60 @deftypefn {Loadable Function} {@var{h} =} convhulln (@var{pts})\n\ 77 @deftypefn {Loadable Function} {@var{h} =} convhulln (@var{pts})\n\
99 } 116 }
100 117
101 Matrix points (args(0).matrix_value ()); 118 Matrix points (args(0).matrix_value ());
102 const octave_idx_type dim = points.columns (); 119 const octave_idx_type dim = points.columns ();
103 const octave_idx_type num_points = points.rows (); 120 const octave_idx_type num_points = points.rows ();
121
122 if (! octave_qhull_dims_ok (dim, num_points, "convhulln"))
123 return retval;
104 124
105 points = points.transpose (); 125 points = points.transpose ();
106 126
107 std::string options; 127 std::string options;
108 128