8000 Segmentation fault · Issue #2684 · wkhtmltopdf/wkhtmltopdf · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
This repository was archived by the owner on Jan 2, 2023. It is now read-only.

Segmentation fault #2684

Closed
alexch1700 opened this issue Nov 24, 2015 · 36 comments
Closed

Segmentation fault #2684

alexch1700 opened this issue Nov 24, 2015 · 36 comments
Labels
Milestone

Comments

@alexch1700
Copy link

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&l
8000
t;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
Copy link

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
Copy link

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
Copy link

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
Copy link
Author

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
Copy link

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

@ashkulz
Copy link
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
Copy link

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
Copy link
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
Copy link
Member
ashkulz commented May 9, 2016

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

@pchk
Copy link
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
Copy link
Member
ashkulz commented May 12, 2016

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

@mikecmpbll
Copy link

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

@ashkulz
Copy link
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
Copy link
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.

@mikecmpbll
Copy link

@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
Copy link
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
Copy link
Member
ashkulz commented May 12, 2016

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

@mikecmpbll
Copy link

@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
Copy link
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
Copy link
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
Copy link
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
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
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
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
Copy link
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 pushed a commit to wkhtmltopdf/qt that referenced this issue Nov 22, 2016
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 me
FE74
mory. 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
Copy link
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
Copy link
mwoynarski commented Dec 14, 2016

@ashkulz I'm experiencing this same issue with 0.12.4

chrisbranson pushed a commit to Current-RMS/wkhtmltopdf that referenced this issue Dec 19, 2016
@fredrikljung93
Copy link

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
Copy link
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
Copy link

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

@urtzai
Copy link
urtzai commented Mar 26, 2019

Still getting Segmentation fault with wkhtmltopdf 0.12.5 (with patched qt)

Has someone any workaround for this version? Thanks

@ETSJustin
Copy link

I am also getting a Segmentation fault with wkhtmltopdf 0.12.5 (with patched qt)
FYI: The HTML document is pretty large (89M)

@ashkulz
Copy link
Member
ashkulz commented Apr 8, 2019

Can you open a new issue with a reproducible test case? Thanks!

@ETSJustin
Copy link

Unfortunately I am unable to provide a reproducible test case as the document in question contains sensitive data.

@ashkulz
Copy link
Member
ashkulz commented Apr 10, 2019

@ETSJustin can you at least make a debug build using ./build compile-docker --debug and post the backtrace?

@ETSJustin
Copy link

@ashkulz unfortunately I failed to do this as I did not understand the steps required to make a debug build as I lack the required skills. I did the following:

git clone https://github.com/wkhtmltopdf/packaging.git
cd packaging/
sudo apt install -y python-yaml docker.io vagrant virtualbox p7zip-full
./build compile-docker --debug

But I got:

usage: build compile-docker [-h] [--debug] target src_dir tgt_dir
build compile-docker: error: too few arguments

TBH, I have no idea what arguments are required!

@oz-freeman
Copy link

Got that error too on Ubintu 16.04 (wkhtmltopdf 0.12.5 with patched qt). Huge source file (over 7M)

Works correctly on Windows with same data

@rkjm4
Copy link
rkjm4 commented May 30, 2019

Got the segfault error on Red Hat 7.6, wkhtmltopdf 0.12.4 (with patched qt).
Looks like this is happening with wkhtmltopdf footer: /bin/wkhtmltopdf --footer-center

@hirasso
Copy link
hirasso commented Nov 10, 2022

I'm having this same error on linux with version 0.12.6:

$ wkhtmltopdf https://example.com/my-website/ wkhtml-test.pdf
Loading pages (1/6)
Segmentation fault========>                                  ] 42%

Locally on my MAC it works just fine, with the same version...

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Development

No branches or pull requests

0