diff options
author | Caolán McNamara <caolanm@redhat.com> | 2017-08-28 13:04:03 +0100 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2017-08-28 16:57:48 +0200 |
commit | 474178acd10a87727ff63f9f5c0bc73d71520af7 (patch) | |
tree | 6b17e355d640e8cad4c941112f679fa53c87cd37 | |
parent | 32e07ada197fb135ae78ee2b7c0c598a356bfabe (diff) |
ofz#3174 disallow header in header
Change-Id: I509fbfe5d7c319f0515896ecfca4183113eef764
Reviewed-on: https://gerrit.libreoffice.org/41635
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Tested-by: Caolán McNamara <caolanm@redhat.com>
-rw-r--r-- | hwpfilter/qa/cppunit/data/fail/header-in-header.hwp | bin | 0 -> 166421 bytes | |||
-rw-r--r-- | hwpfilter/source/hpara.cxx | 15 | ||||
-rw-r--r-- | hwpfilter/source/hwpfile.h | 10 |
3 files changed, 22 insertions, 3 deletions
diff --git a/hwpfilter/qa/cppunit/data/fail/header-in-header.hwp b/hwpfilter/qa/cppunit/data/fail/header-in-header.hwp Binary files differnew file mode 100644 index 000000000000..ef9d8da72e50 --- /dev/null +++ b/hwpfilter/qa/cppunit/data/fail/header-in-header.hwp 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; |