hi,

we have some patches to build our bundled poppler library in LibreOffice
that may be of general interest, see attachments.

regards,
 michael

>From ba6c8024fdc7a7d1407857853e16abea8a721d32 Mon Sep 17 00:00:00 2001
From: Tor Lillqvist <[email protected]>
Date: Thu, 27 Oct 2016 14:27:32 +0200
Subject: [PATCH 1/5] VS 2013 has fmin() and fmax()

---
 poppler/poppler-config.h.in | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/poppler/poppler-config.h.in b/poppler/poppler-config.h.in
index 79d452f..d3891fe 100644
--- a/poppler/poppler-config.h.in
+++ b/poppler/poppler-config.h.in
@@ -186,7 +186,7 @@ char * strtok_r (char *s, const char *delim, char **save_ptr);
 #define GCC_PRINTF_FORMAT(fmt_index, va_index)
 #endif
 
-#if defined(_MSC_VER)
+#if defined(_MSC_VER) && _MSC_VER < 1800
 #define fmax(a, b) std::max(a, b)
 #define fmin(a, b) std::min(a, b)
 #endif
-- 
2.7.4


>From e06d3a33bac8b1a2eb41c6859870ed05659a3b7c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Caol=C3=A1n=20McNamara?= <[email protected]>
Date: Thu, 27 Oct 2016 14:31:20 +0200
Subject: [PATCH 2/5] PSOutputDev.cc: std::max requires <algorithm>

---
 poppler/PSOutputDev.cc | 1 +
 1 file changed, 1 insertion(+)

diff --git a/poppler/PSOutputDev.cc b/poppler/PSOutputDev.cc
index 183e929..51d899f 100644
--- a/poppler/PSOutputDev.cc
+++ b/poppler/PSOutputDev.cc
@@ -48,6 +48,7 @@
 #include <signal.h>
 #include <math.h>
 #include <limits.h>
+#include <algorithm>
 #include "goo/GooString.h"
 #include "goo/GooList.h"
 #include "goo/GooHash.h"
-- 
2.7.4


>From 3b2f63346df5eb78dacfd7b32cb4d7a96a1682cb Mon Sep 17 00:00:00 2001
From: Stephan Bergmann <[email protected]>
Date: Thu, 27 Oct 2016 14:34:37 +0200
Subject: [PATCH 3/5] Work around -fsanitize=enum

...detecting an uninitialized encAlgorithm value is passed into parser->getObj
(where it is presumably ignored for that specific set of arguments) in
XRef::fetch.
---
 poppler/XRef.cc | 1 +
 1 file changed, 1 insertion(+)

diff --git a/poppler/XRef.cc b/poppler/XRef.cc
index e5ecd63..1441a5b 100644
--- a/poppler/XRef.cc
+++ b/poppler/XRef.cc
@@ -295,6 +295,7 @@ void XRef::init() {
   xRefStream = gFalse;
   scannedSpecialFlags = gFalse;
   encrypted = gFalse;
+  encAlgorithm = cryptRC4;
   permFlags = defPermFlags;
   ownerPasswordOk = gFalse;
   rootNum = -1;
-- 
2.7.4


>From 59daacc91417c8699091a3d48f65a5bf7c9e6be2 Mon Sep 17 00:00:00 2001
From: Stephan Bergmann <[email protected]>
Date: Thu, 27 Oct 2016 14:37:11 +0200
Subject: [PATCH 4/5] Work around -fsanitize=shift

---
 poppler/Stream.cc | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/poppler/Stream.cc b/poppler/Stream.cc
index 4a9babe..c3ebda1 100644
--- a/poppler/Stream.cc
+++ b/poppler/Stream.cc
@@ -2972,12 +2972,12 @@ GBool DCTStream::readProgressiveDataUnit(DCTHuffTable *dcHuffTable,
       } else {
 	amp = 0;
       }
-      data[0] += (*prevDC += amp) << scanInfo.al;
+      data[0] += (int) ((unsigned) (*prevDC += amp) << scanInfo.al);
     } else {
       if ((bit = readBit()) == 9999) {
 	return gFalse;
       }
-      data[0] += bit << scanInfo.al;
+      data[0] += (unsigned) bit << scanInfo.al;
     }
     ++i;
   }
@@ -3070,7 +3070,7 @@ GBool DCTStream::readProgressiveDataUnit(DCTHuffTable *dcHuffTable,
 	  j = dctZigZag[i++];
 	}
       }
-      data[j] = amp << scanInfo.al;
+      data[j] = (unsigned) amp << scanInfo.al;
     }
   }
 
@@ -3257,8 +3257,8 @@ void DCTStream::transformDataUnit(Gushort *quantTable,
     v3 = p[6];
     v4 = (dctSqrt1d2 * (p[1] - p[7]) + 128) >> 8;
     v7 = (dctSqrt1d2 * (p[1] + p[7]) + 128) >> 8;
-    v5 = p[3] << 4;
-    v6 = p[5] << 4;
+    v5 = (unsigned) p[3] << 4;
+    v6 = (unsigned) p[5] << 4;
 
     // stage 3
     t = (v0 - v1+ 1) >> 1;
-- 
2.7.4


>From f7761a16a601909423b46fbc8b4b0643e9ef0224 Mon Sep 17 00:00:00 2001
From: Stephan Bergmann <[email protected]>
Date: Thu, 27 Oct 2016 14:38:48 +0200
Subject: [PATCH 5/5] Avoid UBSan warning about undefined downcast

...of this-ptr of in-construction FormFieldSignature while still in the base
FormField ctor, as happens (in the xpdfimport process) during
CppunitTest_xmlsecurity_signing:

> Form.cc:448:12: runtime error: downcast of address 0x60f000000040 which does not point to an object of type 'FormFieldSignature'
> 0x60f000000040: note: object is of type 'FormField'
>  03 00 00 6d  50 84 f2 00 00 00 00 00  03 00 00 00 04 00 00 00  00 00 00 00 01 be be be  07 00 00 00
>               ^~~~~~~~~~~~~~~~~~~~~~~
>               vptr for 'FormField'
>     #0 0x73d7f4 in FormWidgetSignature::FormWidgetSignature(PDFDoc*, Object*, unsigned int, Ref, FormField*) workdir/UnpackedTarball/poppler/poppler/Form.cc:448:12
>     #1 0x741713 in FormField::_createWidget(Object*, Ref) workdir/UnpackedTarball/poppler/poppler/Form.cc:677:34
>     #2 0x73e747 in FormField::FormField(PDFDoc*, Object*, Ref const&, FormField*, std::set<int, std::less<int>, std::allocator<int> >*, FormFieldType) workdir/UnpackedTarball/poppler/poppler/Form.cc:547:7
>     #3 0x74ec2b in FormFieldSignature::FormFieldSignature(PDFDoc*, Object*, Ref const&, FormField*, std::set<int, std::less<int>, std::allocator<int> >*) workdir/UnpackedTarball/poppler/poppler/Form.cc:1383:5
>     #4 0x740d7f in Form::createFieldFromDict(Object*, PDFDoc*, Ref const&, FormField*, std::set<int, std::less<int>, std::allocator<int> >*) workdir/UnpackedTarball/poppler/poppler/Form.cc:1700:19
>     #5 0x750727 in Form::Form(PDFDoc*, Object*) workdir/UnpackedTarball/poppler/poppler/Form.cc:1623:33
>     #6 0x71d440 in Catalog::getForm() workdir/UnpackedTarball/poppler/poppler/Catalog.cc:1042:18
>     #7 0x708572 in Annots::createAnnot(Dict*, Object*) workdir/UnpackedTarball/poppler/poppler/Annot.cc:7218:41
>     #8 0x70772b in Annots::Annots(PDFDoc*, int, Object*) workdir/UnpackedTarball/poppler/poppler/Annot.cc:7128:17
>     #9 0x87f3e9 in Page::getAnnots(XRef*) workdir/UnpackedTarball/poppler/poppler/Page.cc:405:18
>     #10 0x8814b0 in Page::displaySlice(OutputDev*, double, double, int, bool, bool, int, int, int, int, bool, bool (*)(void*), void*, bool (*)(Annot*, void*), void*, bool) workdir/UnpackedTarball/poppler/poppler/Page.cc:611:15
>     #11 0x880ff6 in Page::display(OutputDev*, double, double, int, bool, bool, bool, bool (*)(void*), void*, bool (*)(Annot*, void*), void*, bool) workdir/UnpackedTarball/poppler/poppler/Page.cc:521:3
>     #12 0x88d906 in PDFDoc::displayPage(OutputDev*, int, double, double, int, bool, bool, bool, bool (*)(void*), void*, bool (*)(Annot*, void*), void*, bool) workdir/UnpackedTarball/poppler/poppler/PDFDoc.cc:491:20
>     #13 0x5d59fb in main sdext/source/pdfimport/xpdfwrapper/wrapper_gpl.cxx:142:14
>     #14 0x7f11600ea730 in __libc_start_main (/lib64/libc.so.6+0x20730)
>     #15 0x459388 in _start (instdir/program/xpdfimport+0x459388)
---
 poppler/Form.cc | 57 ++++++++++++++++++++++++++++++++++++++++++---------------
 poppler/Form.h  | 50 +++++++++++++++++++++++++++++++++++++++++++++-----
 2 files changed, 87 insertions(+), 20 deletions(-)

diff --git a/poppler/Form.cc b/poppler/Form.cc
index 8e3b265..18767dd 100644
--- a/poppler/Form.cc
+++ b/poppler/Form.cc
@@ -463,12 +463,11 @@ void FormWidgetSignature::updateWidgetAppearance()
 // FormField
 //========================================================================
 
-FormField::FormField(PDFDoc *docA, Object *aobj, const Ref& aref, FormField *parentA, std::set<int> *usedParents, FormFieldType ty)
+FormField::FormField(PDFDoc *docA, Object *aobj, const Ref& aref, FormField *parentA, FormFieldType ty)
 {
   doc = docA;
   xref = doc->getXRef();
   aobj->copy(&obj);
-  Dict* dict = obj.getDict();
   ref.num = ref.gen = 0;
   type = ty;
   parent = parentA;
@@ -483,7 +482,11 @@ FormField::FormField(PDFDoc *docA, Object *aobj, const Ref& aref, FormField *par
   hasQuadding = gFalse;
 
   ref = aref;
+}
 
+void FormField::init(std::set<int> *usedParents)
+{
+  Dict* dict = obj.getDict();
   Object obj1;
   //childs
   if (dict->lookup("Kids", &obj1)->isArray()) {
@@ -807,9 +810,15 @@ void FormField::updateChildrenAppearance()
 //------------------------------------------------------------------------
 // FormFieldButton
 //------------------------------------------------------------------------
-FormFieldButton::FormFieldButton(PDFDoc *docA, Object *aobj, const Ref& ref, FormField *parent, std::set<int> *usedParents)
-  : FormField(docA, aobj, ref, parent, usedParents, formButton)
+FormFieldButton::FormFieldButton(PDFDoc *docA, Object *aobj, const Ref& ref, FormField *parent)
+  : FormField(docA, aobj, ref, parent, formButton)
+{
+}
+
+void FormFieldButton::init(std::set<int> *usedParents)
 {
+  FormField::init(usedParents);
+
   Dict* dict = obj.getDict();
   active_child = -1;
   noAllOff = false;
@@ -987,9 +996,15 @@ FormFieldButton::~FormFieldButton()
 //------------------------------------------------------------------------
 // FormFieldText
 //------------------------------------------------------------------------
-FormFieldText::FormFieldText(PDFDoc *docA, Object *aobj, const Ref& ref, FormField *parent, std::set<int> *usedParents)
-  : FormField(docA, aobj, ref, parent, usedParents, formText)
+FormFieldText::FormFieldText(PDFDoc *docA, Object *aobj, const Ref& ref, FormField *parent)
+  : FormField(docA, aobj, ref, parent, formText)
+{
+}
+
+void FormFieldText::init(std::set<int> *usedParents)
 {
+  FormField::init(usedParents);
+
   Dict* dict = obj.getDict();
   Object obj1;
   content = NULL;
@@ -1080,9 +1095,15 @@ FormFieldText::~FormFieldText()
 //------------------------------------------------------------------------
 // FormFieldChoice
 //------------------------------------------------------------------------
-FormFieldChoice::FormFieldChoice(PDFDoc *docA, Object *aobj, const Ref& ref, FormField *parent, std::set<int> *usedParents)
-  : FormField(docA, aobj, ref, parent, usedParents, formChoice)
+FormFieldChoice::FormFieldChoice(PDFDoc *docA, Object *aobj, const Ref& ref, FormField *parent)
+  : FormField(docA, aobj, ref, parent, formChoice)
+{
+}
+
+void FormFieldChoice::init(std::set<int> *usedParents)
 {
+  FormField::init(usedParents);
+
   numChoices = 0;
   choices = NULL;
   editedChoice = NULL;
@@ -1383,9 +1404,15 @@ GooString *FormFieldChoice::getSelectedChoice() {
 //------------------------------------------------------------------------
 // FormFieldSignature
 //------------------------------------------------------------------------
-FormFieldSignature::FormFieldSignature(PDFDoc *docA, Object *dict, const Ref& ref, FormField *parent, std::set<int> *usedParents)
-  : FormField(docA, dict, ref, parent, usedParents, formSignature)
+FormFieldSignature::FormFieldSignature(PDFDoc *docA, Object *dict, const Ref& ref, FormField *parent)
+  : FormField(docA, dict, ref, parent, formSignature)
 {
+}
+
+void FormFieldSignature::init(std::set<int> *usedParents)
+{
+  FormField::init(usedParents);
+
   signature = NULL;
 
   signature_info = new SignatureInfo();
@@ -1695,15 +1722,15 @@ FormField *Form::createFieldFromDict (Object* obj, PDFDoc *docA, const Ref& pref
     FormField *field;
 
     if (Form::fieldLookup(obj->getDict (), "FT", &obj2)->isName("Btn")) {
-      field = new FormFieldButton(docA, obj, pref, parent, usedParents);
+      field = FormFieldButton::create(docA, obj, pref, parent, usedParents);
     } else if (obj2.isName("Tx")) {
-      field = new FormFieldText(docA, obj, pref, parent, usedParents);
+      field = FormFieldText::create(docA, obj, pref, parent, usedParents);
     } else if (obj2.isName("Ch")) {
-      field = new FormFieldChoice(docA, obj, pref, parent, usedParents);
+      field = FormFieldChoice::create(docA, obj, pref, parent, usedParents);
     } else if (obj2.isName("Sig")) {
-      field = new FormFieldSignature(docA, obj, pref, parent, usedParents);
+      field = FormFieldSignature::create(docA, obj, pref, parent, usedParents);
     } else { //we don't have an FT entry => non-terminal field
-      field = new FormField(docA, obj, pref, parent, usedParents);
+      field = FormField::create(docA, obj, pref, parent, usedParents);
     }
     obj2.free();
 
diff --git a/poppler/Form.h b/poppler/Form.h
index d467b47..52ff4bf 100644
--- a/poppler/Form.h
+++ b/poppler/Form.h
@@ -264,8 +264,16 @@ protected:
 //------------------------------------------------------------------------
 
 class FormField {
+protected:
+  FormField(PDFDoc *docA, Object *aobj, const Ref& aref, FormField *parent, FormFieldType t);
+  void init(std::set<int> *usedParents);
 public:
-  FormField(PDFDoc *docA, Object *aobj, const Ref& aref, FormField *parent, std::set<int> *usedParents, FormFieldType t=formUndef);
+  static FormField *create(PDFDoc *docA, Object *aobj, const Ref& aref, FormField *parent, std::set<int> *usedParents, FormFieldType t=formUndef)
+  {
+    FormField *f = new FormField(docA, aobj, aref, parent, t);
+    f->init(usedParents);
+    return f;
+  }
 
   virtual ~FormField();
 
@@ -338,8 +346,16 @@ private:
 //------------------------------------------------------------------------
 
 class FormFieldButton: public FormField {
+private:
+  FormFieldButton(PDFDoc *docA, Object *dict, const Ref& ref, FormField *parent);
+  void init(std::set<int> *usedParents);
 public:
-  FormFieldButton(PDFDoc *docA, Object *dict, const Ref& ref, FormField *parent, std::set<int> *usedParents);
+  static FormFieldButton *create(PDFDoc *docA, Object *dict, const Ref& ref, FormField *parent, std::set<int> *usedParents)
+  {
+    FormFieldButton *f = new FormFieldButton(docA, dict, ref, parent);
+    f->init(usedParents);
+    return f;
+  }
 
   FormButtonType getButtonType () { return btype; }
 
@@ -384,8 +400,16 @@ protected:
 //------------------------------------------------------------------------
 
 class FormFieldText: public FormField {
+private:
+  FormFieldText(PDFDoc *docA, Object *dict, const Ref& ref, FormField *parent);
+  void init(std::set<int> *usedParents);
 public:
-  FormFieldText(PDFDoc *docA, Object *dict, const Ref& ref, FormField *parent, std::set<int> *usedParents);
+  static FormFieldText *create(PDFDoc *docA, Object *dict, const Ref& ref, FormField *parent, std::set<int> *usedParents)
+  {
+    FormFieldText *f = new FormFieldText(docA, dict, ref, parent);
+    f->init(usedParents);
+    return f;
+  }
   
   GooString* getContent () { return content; }
   GooString* getContentCopy ();
@@ -422,8 +446,16 @@ protected:
 //------------------------------------------------------------------------
 
 class FormFieldChoice: public FormField {
+private:
+  FormFieldChoice(PDFDoc *docA, Object *aobj, const Ref& ref, FormField *parent);
+  void init(std::set<int> *usedParents);
 public:
-  FormFieldChoice(PDFDoc *docA, Object *aobj, const Ref& ref, FormField *parent, std::set<int> *usedParents);
+  static FormFieldChoice *create(PDFDoc *docA, Object *aobj, const Ref& ref, FormField *parent, std::set<int> *usedParents)
+  {
+    FormFieldChoice *f = new FormFieldChoice(docA, aobj, ref, parent);
+    f->init(usedParents);
+    return f;
+  }
 
   virtual ~FormFieldChoice();
 
@@ -491,8 +523,16 @@ protected:
 //------------------------------------------------------------------------
 
 class FormFieldSignature: public FormField {
+private:
+  FormFieldSignature(PDFDoc *docA, Object *dict, const Ref& ref, FormField *parent);
+  void init(std::set<int> *usedParents);
 public:
-  FormFieldSignature(PDFDoc *docA, Object *dict, const Ref& ref, FormField *parent, std::set<int> *usedParents);
+  static FormFieldSignature *create(PDFDoc *docA, Object *dict, const Ref& ref, FormField *parent, std::set<int> *usedParents)
+  {
+    FormFieldSignature *f = new FormFieldSignature(docA, dict, ref, parent);
+    f->init(usedParents);
+    return f;
+  }
 
   SignatureInfo *validateSignature(bool doVerifyCert, bool forceRevalidation);
 
-- 
2.7.4


_______________________________________________
poppler mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/poppler

Reply via email to