[Libreoffice-commits] core.git: xmlsecurity/inc xmlsecurity/source

Miklos Vajna vmiklos at collabora.co.uk
Fri Oct 21 13:18:30 UTC 2016


 xmlsecurity/inc/pdfio/pdfdocument.hxx    |    2 ++
 xmlsecurity/source/pdfio/pdfdocument.cxx |   21 +++++++++++++++++++--
 2 files changed, 21 insertions(+), 2 deletions(-)

New commits:
commit 834abca71b4899a3ef115df30f68ad2202019247
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Fri Oct 21 14:33:36 2016 +0200

    xmlsecurity PDF export: fix missing /Prev key in the trailer dictionary
    
    "In addition, the added trailer dictionary shall contain a Prev entry
    giving the location of the previous cross-reference section."
    (ISO-32000-1, section 7.5.6). Add it, even if it seems Adobe Acrobat can
    live with not writing it.
    
    Change-Id: I1f53e75ebe7dba4b45b3cf1908b2d3b031ef6b02
    Reviewed-on: https://gerrit.libreoffice.org/30133
    Reviewed-by: Miklos Vajna <vmiklos at collabora.co.uk>
    Tested-by: Jenkins <ci at libreoffice.org>

diff --git a/xmlsecurity/inc/pdfio/pdfdocument.hxx b/xmlsecurity/inc/pdfio/pdfdocument.hxx
index bb132a6..816904f 100644
--- a/xmlsecurity/inc/pdfio/pdfdocument.hxx
+++ b/xmlsecurity/inc/pdfio/pdfdocument.hxx
@@ -44,6 +44,8 @@ class XMLSECURITY_DLLPUBLIC PDFDocument
     std::vector< std::unique_ptr<PDFElement> > m_aElements;
     // List of object offsets we know.
     std::vector<size_t> m_aXRef;
+    /// List of xref offsets we know.
+    std::vector<size_t> m_aStartXRefs;
     PDFTrailerElement* m_pTrailer;
     /// All editing takes place in this buffer, if it happens.
     SvMemoryStream m_aEditBuffer;
diff --git a/xmlsecurity/source/pdfio/pdfdocument.cxx b/xmlsecurity/source/pdfio/pdfdocument.cxx
index d36c9aa..479bc1c 100644
--- a/xmlsecurity/source/pdfio/pdfdocument.cxx
+++ b/xmlsecurity/source/pdfio/pdfdocument.cxx
@@ -414,6 +414,14 @@ bool PDFDocument::Sign(const uno::Reference<security::XCertificate>& xCertificat
         }
         m_aEditBuffer.WriteCharPtr("> ]\n");
     }
+
+    if (!m_aStartXRefs.empty())
+    {
+        // Write location of the previous cross-reference section.
+        m_aEditBuffer.WriteCharPtr("/Prev ");
+        m_aEditBuffer.WriteUInt32AsString(m_aStartXRefs.back());
+    }
+
     m_aEditBuffer.WriteCharPtr(">>\n");
 
     // Write startxref.
@@ -510,6 +518,8 @@ bool PDFDocument::Read(SvStream& rStream)
     // Then we can tokenize the stream.
     rStream.Seek(0);
     bool bInXRef = false;
+    // The next number will be an xref offset.
+    bool bInStartXRef = false;
     while (true)
     {
         rStream.ReadChar(ch);
@@ -584,10 +594,16 @@ bool PDFDocument::Read(SvStream& rStream)
             if (isdigit(ch) || ch == '-')
             {
                 // Numbering object: an integer or a real.
-                m_aElements.push_back(std::unique_ptr<PDFElement>(new PDFNumberElement()));
+                PDFNumberElement* pNumberElement = new PDFNumberElement();
+                m_aElements.push_back(std::unique_ptr<PDFElement>(pNumberElement));
                 rStream.SeekRel(-1);
-                if (!m_aElements.back()->Read(rStream))
+                if (!pNumberElement->Read(rStream))
                     return false;
+                if (bInStartXRef)
+                {
+                    bInStartXRef = false;
+                    m_aStartXRefs.push_back(pNumberElement->GetValue());
+                }
             }
             else if (isalpha(ch))
             {
@@ -688,6 +704,7 @@ bool PDFDocument::Read(SvStream& rStream)
                 }
                 else if (aKeyword == "startxref")
                 {
+                    bInStartXRef = true;
                 }
                 else
                 {


More information about the Libreoffice-commits mailing list