diff options
author | Caolán McNamara <caolanm@redhat.com> | 2022-02-27 21:17:52 +0000 |
---|---|---|
committer | Michael Stahl <michael.stahl@allotropia.de> | 2022-03-03 13:38:06 +0100 |
commit | db916c9f9dc68b25e01fde68a36156644b23ba1f (patch) | |
tree | 909ecdf61dd3decedd2fee7548850815401444b3 | |
parent | 49c8a7b96f47071c1a961b334e70b2f5c7c7b288 (diff) |
ofz#44991 keep paragraph's that failed to load until import is complete
to avoid dangling references to them
Change-Id: Ic8710f63a8cf6a6a665348c7c84bf0b43f0e2c83
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/130643
Tested-by: Jenkins
Reviewed-by: Michael Stahl <michael.stahl@allotropia.de>
(cherry picked from commit 4836ac408b04225b66246671e29a54cd0d6703cf)
-rw-r--r-- | hwpfilter/source/drawing.h | 13 | ||||
-rw-r--r-- | hwpfilter/source/hwpfile.cxx | 9 | ||||
-rw-r--r-- | hwpfilter/source/hwpfile.h | 2 | ||||
-rw-r--r-- | hwpfilter/source/hwpread.cxx | 2 |
4 files changed, 19 insertions, 7 deletions
diff --git a/hwpfilter/source/drawing.h b/hwpfilter/source/drawing.h index b6ed1971672a..7fa700971414 100644 --- a/hwpfilter/source/drawing.h +++ b/hwpfilter/source/drawing.h @@ -316,7 +316,7 @@ static bool LoadCommonHeader(HWPDrawingObject * hdo, unsigned short * link_info) return hmem->skipBlock(size - common_size ) != 0; } -static std::unique_ptr<HWPDrawingObject> LoadDrawingObject(void) +static std::unique_ptr<HWPDrawingObject> LoadDrawingObject(HWPFile& hwpf) { HWPDrawingObject *prev = nullptr; std::unique_ptr<HWPDrawingObject> hdo, head; @@ -355,7 +355,7 @@ static std::unique_ptr<HWPDrawingObject> LoadDrawingObject(void) } if (link_info & HDOFILE_HAS_CHILD) { - hdo->child = LoadDrawingObject(); + hdo->child = LoadDrawingObject(hwpf); if (hdo->child == nullptr) { goto error; @@ -384,6 +384,11 @@ error: { hdo->type = HWPDO_RECT; } + if (hdo->property.pPara) + { + hwpf.move_to_failed(std::unique_ptr<HWPPara>(hdo->property.pPara)); + hdo->property.pPara = nullptr; + } HWPDOFunc(hdo.get(), OBJFUNC_FREE, nullptr, 0); hdo.reset(); @@ -397,7 +402,7 @@ error: } -static bool LoadDrawingObjectBlock(Picture * pic) +static bool LoadDrawingObjectBlock(Picture * pic, HWPFile& hwpf) { int size; if (!hmem->read4b(size)) @@ -423,7 +428,7 @@ static bool LoadDrawingObjectBlock(Picture * pic) !hmem->skipBlock(size - HDOFILE_HEADER_SIZE)) return false; - pic->picinfo.picdraw.hdo = LoadDrawingObject().release(); + pic->picinfo.picdraw.hdo = LoadDrawingObject(hwpf).release(); if (pic->picinfo.picdraw.hdo == nullptr) return false; return true; diff --git a/hwpfilter/source/hwpfile.cxx b/hwpfilter/source/hwpfile.cxx index 439e54d2465a..8b1df15aa3f6 100644 --- a/hwpfilter/source/hwpfile.cxx +++ b/hwpfilter/source/hwpfile.cxx @@ -251,7 +251,7 @@ void HWPFile::ReadParaList(std::vector < HWPPara* > &aplist) aplist.push_back(spNode.release()); spNode.reset( new HWPPara ); } - pfailedlist.push_back(std::move(spNode)); + move_to_failed(std::move(spNode)); } bool HWPFile::ReadParaList(std::vector< std::unique_ptr<HWPPara> > &aplist, unsigned char flag) @@ -285,11 +285,16 @@ bool HWPFile::ReadParaList(std::vector< std::unique_ptr<HWPPara> > &aplist, unsi aplist.push_back(std::move(spNode)); spNode.reset( new HWPPara ); } - pfailedlist.push_back(std::move(spNode)); + move_to_failed(std::move(spNode)); return true; } +void HWPFile::move_to_failed(std::unique_ptr<HWPPara> xPara) +{ + pfailedlist.push_back(std::move(xPara)); +} + void HWPFile::TagsRead() { while (true) diff --git a/hwpfilter/source/hwpfile.h b/hwpfilter/source/hwpfile.h index 3fe580ece7e6..69b5f933b541 100644 --- a/hwpfilter/source/hwpfile.h +++ b/hwpfilter/source/hwpfile.h @@ -258,6 +258,8 @@ class DLLEXPORT HWPFile } void pop_hpara_type() { element_import_stack.pop_back(); } + void move_to_failed(std::unique_ptr<HWPPara> rPara); + private: int compareCharShape(CharShape const *shape); int compareParaShape(ParaShape const *shape); diff --git a/hwpfilter/source/hwpread.cxx b/hwpfilter/source/hwpread.cxx index 1ed8001513af..906246b2b69c 100644 --- a/hwpfilter/source/hwpread.cxx +++ b/hwpfilter/source/hwpread.cxx @@ -463,7 +463,7 @@ bool Picture::Read(HWPFile & hwpf) HMemIODev* pOldMem = hmem; HMemIODev* pNewMem = new HMemIODev(reinterpret_cast<char *>(follow.data()), follow_block_size); hmem = pNewMem; - LoadDrawingObjectBlock(this); + LoadDrawingObjectBlock(this, hwpf); style.cell = picinfo.picdraw.hdo; assert(hmem == pNewMem); delete pNewMem; |