[Libreoffice-commits] core.git: hwpfilter/qa hwpfilter/source

Caolán McNamara caolanm at redhat.com
Mon Aug 28 15:01:39 UTC 2017


 hwpfilter/qa/cppunit/data/fail/header-in-header.hwp |binary
 hwpfilter/source/hpara.cxx                          |   15 ++++++++++++---
 hwpfilter/source/hwpfile.h                          |   10 ++++++++++
 3 files changed, 22 insertions(+), 3 deletions(-)

New commits:
commit 474178acd10a87727ff63f9f5c0bc73d71520af7
Author: Caolán McNamara <caolanm at redhat.com>
Date:   Mon Aug 28 13:04:03 2017 +0100

    ofz#3174 disallow header in header
    
    Change-Id: I509fbfe5d7c319f0515896ecfca4183113eef764
    Reviewed-on: https://gerrit.libreoffice.org/41635
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Caolán McNamara <caolanm at redhat.com>
    Tested-by: Caolán McNamara <caolanm at redhat.com>

diff --git a/hwpfilter/qa/cppunit/data/fail/header-in-header.hwp b/hwpfilter/qa/cppunit/data/fail/header-in-header.hwp
new file mode 100644
index 000000000000..ef9d8da72e50
Binary files /dev/null and b/hwpfilter/qa/cppunit/data/fail/header-in-header.hwp differ
diff --git a/hwpfilter/source/hpara.cxx b/hwpfilter/source/hpara.cxx
index 6b43c3bbf827..7739b9cd0a85 100644
--- a/hwpfilter/source/hpara.cxx
+++ b/hwpfilter/source/hpara.cxx
@@ -229,7 +229,8 @@ std::unique_ptr<HBox> HWPPara::readHBox(HWPFile & hwpf)
                 hbox.reset(new Hidden);
                 break;
             case CH_HEADER_FOOTER:                // 16
-                hbox.reset(new HeaderFooter);
+                if (!hwpf.already_importing_type(CH_HEADER_FOOTER))
+                    hbox.reset(new HeaderFooter);
                 break;
             case CH_FOOTNOTE:                     // 17
                 hbox.reset(new Footnote);
@@ -274,11 +275,19 @@ std::unique_ptr<HBox> HWPPara::readHBox(HWPFile & hwpf)
                 break;
         }
     }
-    if (!hbox || !hbox->Read(hwpf))
+
+    if (!hbox)
+        return nullptr;
+
+    hwpf.push_hpara_type(scflag);
+    bool bRead = hbox->Read(hwpf);
+    hwpf.pop_hpara_type();
+    if (!bRead)
     {
         hbox.reset();
-        return hbox;
+        return nullptr;
     }
+
     if( hh == CH_TEXT_BOX || hh == CH_PICTURE || hh == CH_LINE )
     {
         FBox *fbox = static_cast<FBox *>(hbox.get());
diff --git a/hwpfilter/source/hwpfile.h b/hwpfilter/source/hwpfile.h
index 75f17d19a448..9b002e8abbee 100644
--- a/hwpfilter/source/hwpfile.h
+++ b/hwpfilter/source/hwpfile.h
@@ -25,6 +25,7 @@
 #ifndef INCLUDED_HWPFILTER_SOURCE_HWPFILE_H
 #define INCLUDED_HWPFILTER_SOURCE_HWPFILE_H
 
+#include <algorithm>
 #include <list>
 #include <vector>
 #include <stdio.h>
@@ -252,6 +253,13 @@ class DLLEXPORT HWPFile
           int getMaxSettedPage(){ return m_nMaxSettedPage; }
           void setMaxSettedPage(){ m_nMaxSettedPage = m_nCurrentPage; }
 
+        void push_hpara_type(unsigned char scflag) { element_import_stack.push_back(scflag); }
+        bool already_importing_type(unsigned char scflag) const
+        {
+            return std::find(element_import_stack.begin(), element_import_stack.end(), scflag) != element_import_stack.end();
+        }
+        void pop_hpara_type() { element_import_stack.pop_back(); }
+
     private:
         int compareCharShape(CharShape const *shape);
         int compareParaShape(ParaShape const *shape);
@@ -290,6 +298,8 @@ class DLLEXPORT HWPFile
         std::vector<HeaderFooter*> headerfooters;
         std::vector<ShowPageNum*> pagenumbers;
         std::vector<Table*> tables;
+        //track the stack of HParas types we're currently importing
+        std::vector<unsigned char> element_import_stack;
 
 // for global document handling
         static HWPFile *cur_doc;


More information about the Libreoffice-commits mailing list