[Libreoffice-commits] core.git: sc/inc

Eike Rathke erack at redhat.com
Fri Sep 29 19:17:14 UTC 2017


 sc/inc/scmatrix.hxx |   22 ++++++++++++----------
 1 file changed, 12 insertions(+), 10 deletions(-)

New commits:
commit 6a8bae45f85a4570708fe984ccd7aebad7e389a2
Author: Eike Rathke <erack at redhat.com>
Date:   Fri Sep 29 21:16:00 2017 +0200

    ofz#3487 further limit ScMatrix elements allocation
    
    To 85M elements per matrix. The effective allocation depends on data types and
    distribution and is not statically predictable here. Previous limit (allowing
    128M elements) in the fuzz case allocated 6.5GB temporarily, it now fails early
    with matrix size error. With the case's string data types and changed input
    ranges probably still 4GB could be allocated.
    
    Change-Id: I20ab3cf22705bf022f1c8c8e55b1c412380915dd

diff --git a/sc/inc/scmatrix.hxx b/sc/inc/scmatrix.hxx
index 553c09f0e416..c80ce3333ab0 100644
--- a/sc/inc/scmatrix.hxx
+++ b/sc/inc/scmatrix.hxx
@@ -155,16 +155,18 @@ public:
     /// The maximum number of elements a matrix may have at runtime.
     static size_t GetElementsMax()
     {
-        // TODO: Fix me.
-        return 0x08000000;
-#if 0
-        // Roughly 125MB in total, divided by 8+1 per element => 14M elements.
-        const size_t nMemMax = 0x08000000 / (sizeof(ScMatrixValue) + sizeof(ScMatValType));
-        // With MAXROWCOUNT==65536 and 128 columns => 8M elements ~72MB.
-        const size_t nArbitraryLimit = (size_t)MAXROWCOUNT * 128;
-        // Stuffed with a million rows would limit this to 14 columns.
-        return nMemMax < nArbitraryLimit ? nMemMax : nArbitraryLimit;
-#endif
+        // Arbitrarily assuming 12 bytes per element, 8 bytes double plus
+        // overhead. Stored as an array in an mdds container it's less, but for
+        // strings or mixed matrix it can be much more..
+        constexpr size_t nPerElem = 12;
+        // Arbitrarily assuming 1GB memory. Could be dynamic at some point.
+        constexpr size_t nMemMax = 0x40000000;
+        // With 1GB that's ~85M elements, or 85 whole columns.
+        constexpr size_t nElemMax = nMemMax / nPerElem;
+        // With MAXROWCOUNT==1048576 and 128 columns => 128M elements, 1.5GB
+        constexpr size_t nArbitraryLimit = (size_t)MAXROWCOUNT * 128;
+        // With the constant 1GB from above that's the actual value.
+        return nElemMax < nArbitraryLimit ? nElemMax : nArbitraryLimit;
     }
 
     /** Checks nC or nR for zero and uses GetElementsMax() whether a matrix of


More information about the Libreoffice-commits mailing list