New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Segmentation fault #2684

Closed
alexch1700 opened this Issue Nov 24, 2015 · 27 comments

Comments

Projects
None yet
9 participants
@alexch1700

alexch1700 commented Nov 24, 2015

When I execute the following command line

/usr/local/bin/wkhtmltopdf --encoding 'utf-8' --footer-html '/tmp/footer.html
 --margin-top '5.0' --margin-bottom '10.0' --margin-left '10.0' --margin-right '10.0'
--orientation 'Portrait' --page-size 'A4' /tmp/body.html /tmp/test.pdf

with following footer

<!DOCTYPE html>
Footer text

and following body

<!DOCTYPE html>
<html>
<head>
    <style type="text/css">
        body {
            font-family:helvetica;
            font-size:12px;
        }
        table {
            page-break-inside:avoid;
            width:100%;
        }
        tr {
            page-break-inside:avoid;
        }
    </style>
</head>
<body>

    <div>

        <h2>Lorem ipsum dolor</h2>

        <table cellpadding="0" cellspacing="0">
            <tr>
                <td style="width:20%; padding-bottom:10px; border-top: 1px solid;">Lorem</td>
                <td style="width:80%; padding-bottom:10px; border-top: 1px solid;">Lorem ipsum dolor</td>
            </tr>       
            <tr>
                <td style="width:20%; padding-bottom:10px;">Lorem</td>
                <td style="width:80%; padding-bottom:10px;">Lorem ipsum dolor</td>
            </tr>    
            <tr>
                <td style="width:20%; padding-bottom:10px;">Lorem</td>
                <td style="width:80%; padding-bottom:10px;">Lorem ipsum dolor</td>
            </tr>    
            <tr>
                <td style="width:20%; padding-bottom:10px;">Lorem</td>
                <td style="width:80%; padding-bottom:10px;">Lorem ipsum dolor</td>
            </tr>    
            <tr>
                <td style="width:20%; padding-bottom:10px;">Lorem</td>
                <td style="width:80%; padding-bottom:10px;">Lorem ipsum dolor</td>
            </tr>    
            <tr>
                <td style="width:20%; padding-bottom:10px;">Lorem</td>
                <td style="width:80%; padding-bottom:10px;">Lorem ipsum dolor</td>
            </tr>    
            <tr>
                <td style="width:20%; padding-bottom:10px;">Lorem</td>
                <td style="width:80%; padding-bottom:10px;">Lorem ipsum dolor</td>
            </tr>    
            <tr>
                <td style="width:20%; padding-bottom:10px;">Lorem</td>
                <td style="width:80%; padding-bottom:10px;">Lorem ipsum dolor</td>
            </tr>    
            <tr>
                <td style="width:20%; padding-bottom:10px;">Lorem</td>
                <td style="width:80%; padding-bottom:10px;">Lorem ipsum dolor</td>
            </tr>
        </table>    

        <table cellpadding="0" cellspacing="0">
            <tr>
                <td style="width:20%; padding-bottom:10px;  border-top: 1px solid;" rowspan="4">Lorem</td>
                <td style="width:40%; padding-bottom:10px; border-top: 1px solid;">Lorem</td>
                <td style="width:40%; padding-bottom:10px; border-top: 1px solid;">Lorem</td>                
            </tr>            
            <tr>
                <td style="width:40%; padding-bottom:10px;" >Lorem ipsum dolor</td>
                <td style="width:40%; padding-bottom:10px;" >Lorem ipsum dolor</td>                
            </tr>            
            <tr>
                <td style="width:40%; padding-bottom:10px;" >Lorem ipsum dolor</td>
                <td style="width:40%; padding-bottom:10px;">Lorem ipsum dolor</td>                
            </tr>            
            <tr>
                <td style="width:40%; padding-bottom:10px;">Lorem ipsum dolor</td>
                <td style="width:40%; padding-bottom:10px;">Lorem ipsum dolor</td>                
            </tr>            
        </table>    

        <table cellpadding="0" cellspacing="0">
            <tr>
                <td style="width:20%; padding-bottom:10px; border-top: 1px solid;">Lorem</td>
                <td style="width:40%; padding-bottom:10px; border-top: 1px solid;">Lorem</td>
                <td style="width:40%; padding-bottom:10px; border-top: 1px solid;">Lorem</td>                
            </tr>            
            <tr>
                <td style="width:20%; padding-bottom:10px;"></td>
                <td style="width:40%; padding-bottom:10px; ">
                    Lorem ipsum dolor<br /><br />
                    Lorem ipsum dolor<br /><br />
                    Lorem ipsum dolor
                </td>
                <td style="width:40%; padding-bottom:10px; ">
                    Lorem ipsum dolor<br /><br />
                    Lorem ipsum dolor<br /><br />
                    Lorem ipsum dolor<br /><br />                                        
                    Lorem ipsum dolor<br /><br />                    
                    Lorem ipsum dolor<br /><br />                    
                    Lorem ipsum dolor<br /><br />                    
                    Lorem ipsum dolor<br /><br />                    
                    Lorem ipsum dolor<br /><br />                                                                                                    
                    Lorem ipsum dolor<br /><br />
                    Lorem ipsum dolor<br /><br />
                    Lorem ipsum dolor<br /><br />
                    Lorem ipsum dolor<br /><br />

                </td>                
            </tr>
        </table>    

        <table cellpadding="0" cellspacing="0">
            <tr>
                <td style="width:20%; padding-bottom:10px; border-top: 1px solid;">Lorem</td>
                <td style="width:40%; padding-bottom:10px; border-top: 1px solid;">Lorem</td>
                <td style="width:40%; padding-bottom:10px; border-top: 1px solid;">Lorem</td>
            </tr>
            <tr>
                <td style="width:20%; padding-bottom:10px;"></td>
                <td style="width:40%; padding-bottom:10px; ">
                    Lorem ipsum dolor<br /><br />
                    Lorem ipsum dolor
                </td>
                <td style="width:40%; padding-bottom:10px; " rowspan="3">
                    Lorem ipsum dolor
                </td>                
            </tr>
            <tr>
                <td style="width:20%; padding-bottom:10px;"></td>
                <td style="width:40%; padding-bottom:10px;">Lorem</td>
            </tr>                            
            <tr>
                <td style="width:20%; padding-bottom:10px;"></td>
                <td style="width:40%; padding-bottom:10px;">
                    Lorem ipsum dolor<br />
                    Lorem ipsum dolor<br /><br />
                    Lorem ipsum dolor<br /><br />
                    Lorem ipsum dolor<br />
                    Lorem ipsum dolor<br /><br />
                </td>
            <tr>
        </table>    

        <table cellpadding="0" cellspacing="0">
            <tr>
                <td style="width:20%; padding-bottom:10px; border-top: 1px solid;">Lorem</td>
                <td style="width:40%; padding-bottom:10px; border-top: 1px solid;">Lorem</td>
                <td style="width:40%; padding-bottom:10px; border-top: 1px solid;">Lorem</td>
            </tr>
            <tr>
                <td style="width:20%; padding-bottom:10px;"></td>
                <td style="width:40%; padding-bottom:10px; ">
                    Lorem ipsum dolor<br /><br />
                    Lorem ipsum dolor<br /><br />
                </td>
                <td style="width:40%; padding-bottom:10px; " rowspan="3">
                    Lorem ipsum dolor
                </td>                
            </tr>
            <tr>
                <td style="width:20%; padding-bottom:10px;"></td>
                <td style="width:40%; padding-bottom:10px;">Lorem</td>
            </tr>                            
            <tr>
                <td style="width:20%; padding-bottom:10px;"></td>
                <td style="width:40%; padding-bottom:10px;">
                    Lorem ipsum dolor<br /><br />
                    Lorem ipsum dolor<br /><br />
                    Lorem ipsum dolor
                </td>
            </tr>                                           
        </table>    

        <table cellpadding="0" cellspacing="0">
            <tr>
                <td style="width:100%; padding-bottom:10px; border-top: 1px solid;" colspan="2">Lorem</td>
            </tr>
            <tr>
                <td style="width:20%; padding-bottom:10px;"></td>
                <td style="width:80%; padding-bottom:10px;">
                    Lorem ipsum dolor<br /><br />
                </td>
            </tr>                                           
        </table>    

        <table cellpadding="0" cellspacing="0">
            <tr>
                <td style="width:20%; padding-bottom:10px; border-top: 1px solid;">Lorem</td>
                <td style="width:40%; padding-bottom:10px; border-top: 1px solid;">Lorem</td>
                <td style="width:40%; padding-bottom:10px; border-top: 1px solid;">Lorem</td>
            </tr>
            <tr>
                <td style="width:20%; padding-bottom:10px;"></td>
                <td style="width:40%; padding-bottom:10px;">
                    Lorem ipsum dolor<br /><br />
                    Lorem ipsum dolor<br />
                    Lorem ipsum dolor<br /><br />
                    Lorem ipsum dolor<br />
                    Lorem ipsum dolor<br /><br />
                    Lorem ipsum dolor<br /><br />
                    Lorem ipsum dolor<br /><br />
                    Lorem ipsum dolor<br /><br />
                    Lorem ipsum dolor<br /><br />
                    Lorem ipsum dolor<br />
                    Lorem ipsum dolor<br /><br />
                    Lorem ipsum dolor<br /><br />
                </td>
                <td style="width:40%; padding-bottom:10px; ">
                    Lorem ipsum dolor
                </td>
            </tr>
            <tr>
                <td style="width:20%; padding-bottom:10px;"></td>
                <td style="width:40%; padding-bottom:10px;">Lorem</td>
                <td style="width:40%; padding-bottom:10px;">Lorem</td>
            </tr>
            <tr>
                <td style="width:20%; padding-bottom:10px;"></td>
                <td style="width:40%; padding-bottom:10px;">
                    Lorem ipsum dolor<br />
                    Lorem ipsum dolor<br /><br />
                    Lorem ipsum dolor<br />
                    Lorem ipsum dolor<br /><br />
                </td>
                <td style="width:40%; padding-bottom:10px; ">
                    Lorem ipsum dolor
                </td>
            </tr>
        </table>    

        <table cellpadding="0" cellspacing="0">
            <tr>
                <td style="width:20%; padding-bottom:10px; border-top: 1px solid;">Lorem</td>
                <td style="width:40%; padding-bottom:10px; border-top: 1px solid;">Lorem</td>
                <td style="width:40%; padding-bottom:10px; border-top: 1px solid;">Lorem</td>
            </tr>
            <tr>
                <td style="width:20%; padding-bottom:10px;"></td>
                <td style="width:40%; padding-bottom:10px; ">
                    Lorem ipsum dolor<br /><br />
                </td>
                <td style="width:40%; padding-bottom:10px; ">
                    Lorem ipsum dolor<br />
                    Lorem ipsum dolor<br /><br />
                    Lorem ipsum dolor<br /><br />
                    Lorem ipsum dolor<br />
                    Lorem ipsum dolor<br /><br />
                    Lorem ipsum dolor<br />
                    Lorem ipsum dolor<br /><br />
                    Lorem ipsum dolor<br />
                    Lorem ipsum dolor<br /><br />
                </td>
            </tr>
            <tr>
                <td style="width:20%; padding-bottom:10px;">Lorem</td>
                <td style="width:80%; padding-bottom:10px;" colspan="2">Lorem ipsum dolor</td>
            </tr>
        </table>    

        <table cellpadding="0" cellspacing="0">
            <tr>
                <td style="width:20%; padding-bottom:10px; border-top:1px solid;">Lorem</td>
                <td style="width:80%; padding-bottom:10px; border-top:1px solid;" colspan="2"></td>
            </tr>
            <tr>
                <td style="width:20%; padding-bottom:10px;"></td>
                <td style="width:80%; padding-bottom:10px;" colspan="2">
                        Lorem ipsum dolor<br /><br />
                        Lorem ipsum dolor<br /><br />
                        Lorem ipsum dolor<br /><br />
                </td>
            </tr>
        </table>       

        <table cellpadding="0" cellspacing="0"> 
            <tr>
                <td style="width:100%; padding-bottom:10px; border-top: 1px solid;" colspan="2">Lorem</td>
            </tr>       
            <tr>
                <td style="width:20%; padding-bottom:10px;"></td>
                <td style="width:80%; padding-bottom:10px; padding-right:10px;">
                    Lorem ipsum dolor<br /><br />
                    Lorem ipsum dolor<br /><br />
                    Lorem ipsum dolor<br /><br />
                </td>
            </tr>
        </table>    

    </div>

</body>
</html>

a Segmentation error (core dumped) occure.

Here is the execution trace

Loading pages (1/6)
[>                                                           ] 0%
[======>                                                     ] 10%
[==============================>                             ] 50%
[============================================================] 100%
Counting pages (2/6)                                               
[============================================================] Object 1 of 1
Resolving links (4/6)                                                       
[============================================================] Object 1 of 1
Loading headers and footers (5/6)                                           
[=>                                                          ] 3%
[===>                                                        ] 6%
[======>                                                     ] 10%
[=============>                                              ] 23%
[========================>                                   ] 40%
[===============================>                            ] 53%
[==========================================>                 ] 70%
[=================================================>          ] 83%
[============================================================] 100%
Printing pages (6/6)                                               
[>                                                           ] Preparing
[===================>                                        ] Page 1 of 3
[=======================================>                    ] Page 2 of 3
[============================================================] Page 3 of 3
[============================================================] Page 4 of 3

where we can see Printing Page 4 of 3.

I work on Ubuntu 12.04 with wkhtmltopdf 0.12.2.1 (with patched qt).

Thank you for your help

@mihaiscurtucb

This comment has been minimized.

mihaiscurtucb commented Apr 19, 2016

Sorry to bump this, but I'm encountering the exact same issue with some html i'm generating and I couldn't find any answers.

Did you manage to fix it, @alexch1700?

@mikecmpbll

This comment has been minimized.

mikecmpbll commented May 5, 2016

Also getting a segmentation fault occasionally for certain HTML inputs. It's hard to find a common thread between those which fail and often just changing a handful of characters, or some properties of the conversion, will make it succeed.

A reproduceable example input HTML here: https://gist.github.com/mikecmpbll/3dd488aa2cda1984111c788c358b110d

Which I run like this:

$ /usr/local/bin/wkhtmltopdf --disable-smart-shrinking --page-size A4 --margin-top 0.5in --margin-right 0.5in --margin-bottom 0.5in --margin-left 0.5in --encoding UTF-8 --viewport-size 1280x1024 pdf_fail.html fail.pdf
Loading pages (1/6)
Counting pages (2/6)                                               
Segmentation fault===========================================] Object 1 of 1

This happens for me on 32 bit Ubuntu 12.04.5 and 64 bit Ubuntu 14.04.4 with wkhtmltopdf 0.12.3 (with patched qt), but it doesn't fail on OSX with 0.12.3.

@mikecmpbll

This comment has been minimized.

mikecmpbll commented May 5, 2016

just posted a $500 bounty for this issue (my issue, if it's different) for anyone who's able to get to the bottom of this. https://www.bountysource.com/issues/28572614-segmentation-fault

@alexch1700

This comment has been minimized.

alexch1700 commented May 5, 2016

Not a solution to this issue but a workaround is to try to change margin_bottom in a loop.

Context :

  • position [6] of command is the value of margin_bottom
  • exit status when this error appear is -11

Python code sample :

nb_count = 0
status = -11
while status == -11 and nb_count < 10:
     command[6] = str(margin_bottom+nb_count*0.3)
     status = subprocess.call(command, stderr=stderr_fd)
     nb_count += 1

It's not a good solution but it avoids errors waiting a better proposition.

@mikecmpbll

This comment has been minimized.

mikecmpbll commented May 6, 2016

@alexch1700 : nice idea. at the moment we're falling back to rendering the HTML but this could be better, thanks.

@ashkulz

This comment has been minimized.

Member

ashkulz commented May 6, 2016

Hmm, it's possible that the issue is already fixed -- can you see if the patch I posted on another issue fixes it for you? Please refer to the comments below, so that I can confirm that everything is OK with this change.

@mikecmpbll

This comment has been minimized.

mikecmpbll commented May 6, 2016

same error with that patch, for me. i notice mine seems somewhat different to these issues as i don't get the characteristic "Page 4 of 3" (e.g.) in my output as it fails earlier during counting pages ..

@ashkulz

This comment has been minimized.

Member

ashkulz commented May 9, 2016

@mikecmpbll: it looks like using normalize.css v3.0.2 is causing the crash. Just before the crash, you can see a lot of memory being allocated -- I suspect it is segfaulting because of that as I checked only on Windows, probably true for Linux as well.

Not sure what is exactly causing the problem, but you can try bisecting by removing half of the CSS, check if it works and repeat till you find the offender. Until the browser engine is upgraded, you should avoid certain CSS constructs.

@ashkulz

This comment has been minimized.

Member

ashkulz commented May 9, 2016

For the original reporters @alexch1700 and @mihaiscurtucb -- does the patch mentioned in the issue work for you?

@pchk

This comment has been minimized.

pchk commented May 11, 2016

@mikecmpbll please check the pull request mentioned above.
Or you can apply this patch for test if this memory usage reduction solves your problem. If not i will search for another places to fix that.

diff --git a/src/gui/painting/qprintengine_pdf.cpp b/src/gui/painting/qprintengine_pdf.cpp
index 751e4ce..e150a83 100644
--- a/src/gui/painting/qprintengine_pdf.cpp
+++ b/src/gui/painting/qprintengine_pdf.cpp
@@ -833,7 +833,29 @@ public:

 };

+bool QPdfEnginePrivate::smartCompressDeflate(const char *source, int size, QByteArray& compressed, unsigned long maxSize)
+{
+    if (maxSize == 0) {
+        maxSize = ::compressBound(size);
+    }
+
+    unsigned long destLen = min(static_cast<unsigned long>(QPdfPage::chunkSize()), maxSize);
+
+    while (true) {
+        compressed.resize(destLen);
+        if (Z_OK == ::compress(reinterpret_cast<Bytef *>(compressed.data()), &destLen, reinterpret_cast<const Bytef *>(source), size)) {
+            compressed.truncate(destLen);
+            break;
+        }
+        if (static_cast<unsigned long>(compressed.size()) >= maxSize) {
+            compressed.clear();
+            return false;
+        }
+        destLen = min(static_cast<unsigned long>(compressed.size()) * 2, maxSize);
+    }

+    return true;
+}

 /*!
  * Adds an image to the pdf and return the pdf-object id. Returns -1 if adding the image failed.
@@ -907,33 +929,25 @@ int QPdfEnginePrivate::addImage(const QImage &img, bool *bitmap, qint64 serial_n
         if (noneScaled && noneScaled->rect() != image.rect()) {
             QByteArray imageData2;
             convertImage(*noneScaled, imageData2);
-            uLongf len = imageData2.size();
-            uLongf destLen = len + len/100 + 13; // zlib requirement
-            Bytef* dest = new Bytef[destLen];
-            if (Z_OK == ::compress(dest, &destLen, (const Bytef*) imageData2.data(), (uLongf)len) &&
-                (uLongf)destLen < target) {
-                imageData=imageData2;
-                target=destLen;
-                dct=false;
-                uns=true;
+            QByteArray compressed;
+            if (smartCompressDeflate(imageData2.data(), imageData2.size(), compressed, target)) {
+                imageData = imageData2;
+                target = compressed.size();
+                dct = false;
+                uns = true;
             }
-            delete[] dest;
         }

         {
             QByteArray imageData2;
             convertImage(image, imageData2);
-            uLongf len = imageData2.size();
-            uLongf destLen = len + len/100 + 13; // zlib requirement
-            Bytef* dest = new Bytef[destLen];
-            if (Z_OK == ::compress(dest, &destLen, (const Bytef*) imageData2.data(), (uLongf)len) &&
-                (uLongf)destLen < target) {
-                imageData=imageData2;
-                target=destLen;
-                dct=false;
-                uns=false;
+            QByteArray compressed;
+            if (smartCompressDeflate(imageData2.data(), imageData2.size(), compressed, target)) {
+                imageData = imageData2;
+                target = compressed.size();
+                dct = false;
+                uns = false;
             }
-            delete[] dest;
         }


@@ -1182,16 +1196,13 @@ int QPdfEnginePrivate::writeCompressed(const char *src, int len)
 {
 #ifndef QT_NO_COMPRESS
     if(doCompress) {
-        uLongf destLen = len + len/100 + 13; // zlib requirement
-        Bytef* dest = new Bytef[destLen];
-        if (Z_OK == ::compress(dest, &destLen, (const Bytef*) src, (uLongf)len)) {
-            stream->writeRawData((const char*)dest, destLen);
+        QByteArray compressed;
+        if (smartCompressDeflate(src, len, compressed)) {
+            stream->writeRawData((const char*)compressed.data(), compressed.size());
         } else {
             qWarning("QPdfStream::writeCompressed: Error in compress()");
-            destLen = 0;
         }
-        delete [] dest;
-        len = destLen;
+        len = compressed.size();
     } else
 #endif
     {
diff --git a/src/gui/painting/qprintengine_pdf_p.h b/src/gui/painting/qprintengine_pdf_p.h
index 773706d..7db5e54 100644
--- a/src/gui/painting/qprintengine_pdf_p.h
+++ b/src/gui/painting/qprintengine_pdf_p.h
@@ -233,6 +233,7 @@ private:
         streampos += data.size();
     }

+    bool smartCompressDeflate(const char *source, int size, QByteArray& compressed, unsigned long maxSize = 0);
     int writeCompressed(const char *src, int len);
     inline int writeCompressed(const QByteArray &data) { return writeCompressed(data.constData(), data.length()); }
     int writeCompressed(QIODevice *dev);
@ashkulz

This comment has been minimized.

Member

ashkulz commented May 12, 2016

@pchk: what does the PR have to do with the crash?

@mikecmpbll

This comment has been minimized.

mikecmpbll commented May 12, 2016

@pchk : i gave it a go but same error for me :)

@ashkulz

This comment has been minimized.

Member

ashkulz commented May 12, 2016

@mikecmpbll: your crash is linked to normalize.css, I'm guessing it is so because of weird specifications (e.g. -10000px margin). As wkhtmltopdf uses an older version of WebKit, it won't really get fixed until the underlying WebKit gets updated. I'd recommend you remove it and use wkhtmltopdf-specific CSS, possibly using --user-style-sheet.

@ashkulz

This comment has been minimized.

Member

ashkulz commented May 12, 2016

Marking as duplicate unless the original reporters @alexch1700 and @mihaiscurtucb can confirm otherwise -- in which case, please post a test case.

@ashkulz ashkulz closed this May 12, 2016

@ashkulz ashkulz added Duplicate and removed NeedInfo labels May 12, 2016

@mikecmpbll

This comment has been minimized.

mikecmpbll commented May 12, 2016

@ashkulz : sorry, wasn't ignoring your earlier comment, i'm going to do the css bisection as suggested just haven't got around to it yet! thanks so much for pointing this out to me 😌

@pchk

This comment has been minimized.

pchk commented May 12, 2016

@ashkulz PR reduces memory consumption like a reason for that crash.
@mikecmpbll if the bounty is active and you are still interested to fix that without any workarounds i already have another improvements for that case. Please comment your thoughts on that moment.

@ashkulz

This comment has been minimized.

Member

ashkulz commented May 12, 2016

@pchk: please address the comments made in the PR.

@mikecmpbll

This comment has been minimized.

mikecmpbll commented May 12, 2016

@pchk : sure, if the pdf can be rendered without changes that'll save me some time and would certainly be eligible for the bounty. (i don't know that it's possible though for the reasons ashkulz says about WebKit?)

@pchk

This comment has been minimized.

pchk commented May 14, 2016

Finally got it fixed. Updated the pull request.
@mikecmpbll please check this patch. I am sure this will solve your problem.
Please approve that.

diff --git a/src/3rdparty/webkit/Source/WebCore/rendering/RenderBlock.cpp b/src/3rdparty/webkit/Source/WebCore/rendering/RenderBlock.cpp
index d8412db..5fd713c 100644
--- a/src/3rdparty/webkit/Source/WebCore/rendering/RenderBlock.cpp
+++ b/src/3rdparty/webkit/Source/WebCore/rendering/RenderBlock.cpp
@@ -3234,6 +3234,8 @@ void RenderBlock::removeFloatingObjectsBelow(FloatingObject* lastFloat, int logi
         floatingObjectSet.removeLast();
         ASSERT(!curr->m_originatingLine);
         delete curr;
+        if (floatingObjectSet.isEmpty())
+            break;
         curr = floatingObjectSet.last();
     }
 }
@ashkulz

This comment has been minimized.

Member

ashkulz commented May 14, 2016

@mikecmpbll: verify if the crash gets fixed with this and no other backports are required. It feels really good to get code contributions from @pchk -- wish more people posted bounties 😄

@mikecmpbll

This comment has been minimized.

mikecmpbll commented May 14, 2016

@pchk: fantastic! 😍 compiled it just now and verified that it no longer seg faults—go claim bounty and i'll confirm it :)

⭐! thanks also @ashkulz!

pchk added a commit to pchk/qt that referenced this issue May 14, 2016

Added ARGB32_Premultiplied format support
In the case when original image comes to our code in format ARGB32_Premultiplied we convert it to format ARGB32. The conversion constructs new QImage object and allocates buffer for it. Conversion will be done for scaled and nonScaled QImage objects.
If we support ARGB32_Premultiplied two unnecessary allocations will be skipped saving us a lot memory. Ex.:
In test fail.html mentioned in wkhtmltopdf/wkhtmltopdf#2684 i saw that
large nonScaled QImage consums memory amount about 300mb (8000px x 10000px
4 byte ARGB32_Premultiplied). And when we convert it into ARGB32 it
allocated another ~ 300mb of memory for new QImage object.
But we can work with that format wothout conversion.

pchk added a commit to pchk/qt that referenced this issue May 14, 2016

Added ARGB32_Premultiplied format support
In the case when original image comes to our code in format
ARGB32_Premultiplied we convert it to format ARGB32. The conversion
constructs new QImage object and allocates buffer for it. Conversion will
be done for scaled and nonScaled QImage objects.
If we support ARGB32_Premultiplied two unnecessary allocations will be
skipped saving us a lot memory. Ex.:
In test fail.html mentioned in wkhtmltopdf/wkhtmltopdf#2684 i saw that
large nonScaled QImage consums memory amount about 300mb (8000px x 10000px
4-byte ARGB32_Premultiplied). And when we convert it into ARGB32 it
allocates another ~ 300mb of memory for new QImage object.
But we can work with that format wothout conversion.

pchk added a commit to pchk/qt that referenced this issue May 14, 2016

Use smart-growing buffer size for compression
Usally buffer size that fits all compressed data is much lesser that
source uncompressed data size.
This routine has initial size of buffer = 10mb. Usually is is enough to
compress any image that comes to a printer. In the worst case the buffer
will grow up to :;compressBound result thats guarantees to fit all
compressed data.
Ex:
In pdf_fail.html(235kb) metioned in wkhtmltopdf/wkhtmltopdf#2684 nonScaled image
~300mb, real buffer size needed for compression will be ~3mb.
@ashkulz

This comment has been minimized.

Member

ashkulz commented May 15, 2016

Just to confirm: I think you wouldn't get this issue with 0.13 alpha, as it has an updated browser engine. But good that these patches got backported.

ashkulz added a commit to wkhtmltopdf/qt that referenced this issue Nov 22, 2016

Added ARGB32_Premultiplied format support
In the case when original image comes to our code in format
ARGB32_Premultiplied we convert it to format ARGB32. The conversion
constructs new QImage object and allocates buffer for it. Conversion will
be done for scaled and nonScaled QImage objects.
If we support ARGB32_Premultiplied two unnecessary allocations will be
skipped saving us a lot memory. Ex.:
In test fail.html mentioned in wkhtmltopdf/wkhtmltopdf#2684 i saw that
large nonScaled QImage consums memory amount about 300mb (8000px x 10000px
4-byte ARGB32_Premultiplied). And when we convert it into ARGB32 it
allocates another ~ 300mb of memory for new QImage object.
But we can work with that format wothout conversion.

ashkulz added a commit that referenced this issue Nov 22, 2016

@ashkulz ashkulz added Fixed and removed Duplicate labels Nov 22, 2016

@ashkulz ashkulz added this to the 0.12.4 milestone Nov 22, 2016

@ashkulz

This comment has been minimized.

Member

ashkulz commented Nov 23, 2016

0.12.4 has been released, which should contain the fix for this issue. Please report back if it is not solved with the above version.

@mwoynarski

This comment has been minimized.

mwoynarski commented Dec 14, 2016

@ashkulz I'm experiencing this same issue with 0.12.4

chrisbranson added a commit to Current-RMS/wkhtmltopdf that referenced this issue Dec 19, 2016

@fredrikljung93

This comment has been minimized.

fredrikljung93 commented Mar 6, 2017

I'm using 0.12.4 and I have similar problems in the following issue #3366

I am however not using normalize.css, and my workaround so far is to add many
at the end of the body (which results in an extra empty page)

@SpOOnman

This comment has been minimized.

SpOOnman commented Jun 7, 2018

I also had this problem with several documents and wkhtmltopdf 0.12.4 : "Page 4 of 3". I think this commit can solve this situation: 6f77c46. It is a part of wkhtmltox-0.12.5-rc. I've downloaded binary for CentOS6, I've tested this today and it passed! With the same input data 0.12.4 fails and 0.12.5 works fine. I keep my fingers crossed that this is the definitive fix! 🤞

@ronniescs

This comment has been minimized.

ronniescs commented Aug 30, 2018

Finally 0.12.5 resolved this for me as well!
After months of manual workarounds. 🤞

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment