[gnumeric] MUNIT: Restrict size to prevent trashing the whole system.



commit 2aa3decc245bb75543c0c549e5379656f265962c
Author: Morten Welinder <terra gnome org>
Date:   Mon Jan 14 20:10:45 2013 -0500

    MUNIT: Restrict size to prevent trashing the whole system.
    
    This limits the size to what would fit on the sheet.  That's probably
    good enough even though calculations could be done without placing the
    matrix in a sheet.

 NEWS                        |    1 +
 plugins/fn-math/ChangeLog   |    5 +++++
 plugins/fn-math/functions.c |    4 +++-
 3 files changed, 9 insertions(+), 1 deletions(-)
---
diff --git a/NEWS b/NEWS
index 110409c..a656888 100644
--- a/NEWS
+++ b/NEWS
@@ -23,6 +23,7 @@ Morten:
 	* Improve EIGEN.   [#687926]
 	* Improve handling of unknown functions.  [#109442]
 	* Add LINSOLVE function.
+	* Restrict size of MUNIT to avoid thrashing the system.  [#625544]
 
 --------------------------------------------------------------------------
 Gnumeric 1.12.0
diff --git a/plugins/fn-math/ChangeLog b/plugins/fn-math/ChangeLog
index bf68185..b90fdf6 100644
--- a/plugins/fn-math/ChangeLog
+++ b/plugins/fn-math/ChangeLog
@@ -1,3 +1,8 @@
+2013-01-14  Morten Welinder  <terra gnome org>
+
+	* functions.c (gnumeric_munit): Restrict size to what would fit in
+	the sheet it's called from.
+
 2013-01-13  Morten Welinder  <terra gnome org>
 
 	* functions.c (gnumeric_linsolve): New function.
diff --git a/plugins/fn-math/functions.c b/plugins/fn-math/functions.c
index 9de078c..6b0efaa 100644
--- a/plugins/fn-math/functions.c
+++ b/plugins/fn-math/functions.c
@@ -2841,7 +2841,9 @@ gnumeric_munit (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
 	 * This provides some protection against bogus sizes and
 	 * running out of memory.
 	 */
-	if (n * n >= G_MAXINT)
+	if (n * n >= G_MAXINT ||
+	    n > gnm_sheet_get_max_cols (ei->pos->sheet) ||
+	    n > gnm_sheet_get_max_rows (ei->pos->sheet)) /* Arbitrary */
 		return value_new_error_NUM (ei->pos);
 
 	ni = (int)n;



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]