[Libreoffice-commits] core.git: libreofficekit/source

Andrzej Hunt andrzej.hunt at collabora.com
Mon Jul 28 07:34:07 PDT 2014


 libreofficekit/source/gtk/lokdocview.c |   22 ++++++++++++++++++----
 1 file changed, 18 insertions(+), 4 deletions(-)

New commits:
commit c1d9fe079a32a0515683236f91892c98ee837f8b
Author: Andrzej Hunt <andrzej.hunt at collabora.com>
Date:   Mon Jul 28 16:29:43 2014 +0200

    Prevent LOK DocView crash if document too large.
    
    There seems to be a maximum size that gdk's pixbuf
    can handle, however I have been unable to find any
    documentatation. Seeing as the current implementation
    isn't realistically useable anyway, we might as well
    set a hard limit here (in practice we'd have much smaller
    tiles + compositing).
    
    Specifically extras/source/shellnew/soffice.ods will fail
    without this patch.
    
    Change-Id: I6ac495adca8e15878989375ef8b2de472788279a

diff --git a/libreofficekit/source/gtk/lokdocview.c b/libreofficekit/source/gtk/lokdocview.c
index cdc2339..e8fe526 100644
--- a/libreofficekit/source/gtk/lokdocview.c
+++ b/libreofficekit/source/gtk/lokdocview.c
@@ -108,12 +108,26 @@ void renderDocument( LOKDocView* pDocView )
 
     pDocView->pDocument->pClass->getDocumentSize( pDocView->pDocument, &nWidth, &nHeight );
 
-    // Draw the whole document at once (for now)
-
     // TODO: we really should scale by screen DPI here -- 10 seems to be a vaguely
     // correct factor for my screen at least.
-    nRenderWidth = nWidth * pDocView->fZoom / 10;
-    nRenderHeight = nHeight * pDocView->fZoom / 10;
+    const float fScaleFactor = 0.1;
+
+    // Various things blow up if we try to draw too large a tile,
+    // this size seems to be safe. (Very rare/unlikely that
+    const int nMaxWidth = 100000;
+    if ( nWidth * fScaleFactor > nMaxWidth )
+    {
+        nWidth = nMaxWidth;
+    }
+    if ( nHeight * fScaleFactor > nMaxWidth )
+    {
+        nHeight = nMaxWidth;
+    }
+
+    // Draw the whole document at once (for now)
+
+    nRenderWidth = nWidth * pDocView->fZoom * fScaleFactor;
+    nRenderHeight = nHeight * pDocView->fZoom * fScaleFactor;
 
     pDocView->pPixBuf = gdk_pixbuf_new( GDK_COLORSPACE_RGB,
                                         TRUE, 8,


More information about the Libreoffice-commits mailing list