hwpfilter/source/drawing.h   |   13 +++++++++----
 hwpfilter/source/hwpfile.cxx |    9 +++++++--
 hwpfilter/source/hwpfile.h   |    2 ++
 hwpfilter/source/hwpread.cxx |    2 +-
 4 files changed, 19 insertions(+), 7 deletions(-)

New commits:
commit e650d99c199fc2f453eb239e1c35e4a82a92900b
Author:     Caolán McNamara <[email protected]>
AuthorDate: Sun Feb 27 21:17:52 2022 +0000
Commit:     Michael Stahl <[email protected]>
CommitDate: Tue Mar 1 18:11:53 2022 +0100

    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/+/130642
    Tested-by: Jenkins
    Reviewed-by: Michael Stahl <[email protected]>

diff --git a/hwpfilter/source/drawing.h b/hwpfilter/source/drawing.h
index c7526a4c591e..54d98bbf5262 100644
--- a/hwpfilter/source/drawing.h
+++ b/hwpfilter/source/drawing.h
@@ -315,7 +315,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;
@@ -354,7 +354,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;
@@ -383,6 +383,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();
 
@@ -396,7 +401,7 @@ error:
 }
 
 
-static bool LoadDrawingObjectBlock(Picture * pic)
+static bool LoadDrawingObjectBlock(Picture * pic, HWPFile& hwpf)
 {
     int size;
     if (!hmem->read4b(size))
@@ -422,7 +427,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 4ff62fa9db30..15f73fbec6ec 100644
--- a/hwpfilter/source/hwpfile.cxx
+++ b/hwpfilter/source/hwpfile.cxx
@@ -238,7 +238,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));
 }
 
 void HWPFile::ReadParaList(std::vector< std::unique_ptr<HWPPara> > &aplist, 
unsigned char flag)
@@ -272,7 +272,12 @@ void 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));
+}
+
+void HWPFile::move_to_failed(std::unique_ptr<HWPPara> xPara)
+{
+    pfailedlist.push_back(std::move(xPara));
 }
 
 void HWPFile::TagsRead()
diff --git a/hwpfilter/source/hwpfile.h b/hwpfilter/source/hwpfile.h
index 4e92185a11eb..7e98c1e20271 100644
--- a/hwpfilter/source/hwpfile.h
+++ b/hwpfilter/source/hwpfile.h
@@ -253,6 +253,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 8e4a96c726d0..d0df1cf97ba2 100644
--- a/hwpfilter/source/hwpread.cxx
+++ b/hwpfilter/source/hwpread.cxx
@@ -494,7 +494,7 @@ bool Picture::Read(HWPFile & hwpf)
         if (pictype == PICTYPE_DRAW)
         {
             auto xGuard(std::make_unique<ChangeMemGuard>(follow.data(), 
follow_block_size));
-            LoadDrawingObjectBlock(this);
+            LoadDrawingObjectBlock(this, hwpf);
             style.cell = picinfo.picdraw.hdo;
             xGuard.reset();
         }

Reply via email to