[Libreoffice-commits] core.git: Branch 'libreoffice-5-4' - 2 commits - hwpfilter/source

Caolán McNamara caolanm at redhat.com
Mon Feb 26 09:12:23 UTC 2018


 hwpfilter/source/hcode.cxx   |   28 +++++++++++-----------------
 hwpfilter/source/hinfo.cxx   |   11 ++++++-----
 hwpfilter/source/hinfo.h     |    2 +-
 hwpfilter/source/hpara.cxx   |    4 ++--
 hwpfilter/source/hwpfile.cxx |    6 +++---
 hwpfilter/source/hwpfile.h   |    5 ++---
 6 files changed, 25 insertions(+), 31 deletions(-)

New commits:
commit b434bda77878e87f1eb8efeaab3dd0e5f5c4f420
Author: Caolán McNamara <caolanm at redhat.com>
Date:   Sat Feb 24 20:43:12 2018 +0000

    forcepoint #8 ensure ColumnDef lifetime
    
    Change-Id: Idb0c7b1530dc57f4d7c14751f1b76caecc3b03a6
    Reviewed-on: https://gerrit.libreoffice.org/50290
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Miklos Vajna <vmiklos at collabora.co.uk>

diff --git a/hwpfilter/source/hinfo.cxx b/hwpfilter/source/hinfo.cxx
index 26e2847ff048..48a0999b7108 100644
--- a/hwpfilter/source/hinfo.cxx
+++ b/hwpfilter/source/hinfo.cxx
@@ -204,6 +204,7 @@ ParaShape::ParaShape()
     , pspacing_next(0)
     , condense(0)
     , arrange_type(0)
+    , xColdef(new ColumnDef)
     , shade(0)
     , outline(0)
     , outline_continue(0)
@@ -243,17 +244,17 @@ void ParaShape::Read(HWPFile & hwpf)
             return;
         tab.position = tmp16;
     }
-    hwpf.Read1b(&coldef.ncols, 1);
-    hwpf.Read1b(&coldef.separator, 1);
+    hwpf.Read1b(&(xColdef->ncols), 1);
+    hwpf.Read1b(&(xColdef->separator), 1);
     if (!hwpf.Read2b(tmp16))
         return;
-    coldef.spacing = tmp16;
+    xColdef->spacing = tmp16;
     if (!hwpf.Read2b(tmp16))
         return;
-    coldef.columnlen = tmp16;
+    xColdef->columnlen = tmp16;
     if (!hwpf.Read2b(tmp16))
         return;
-    coldef.columnlen0 = tmp16;
+    xColdef->columnlen0 = tmp16;
     hwpf.Read1b(&shade, 1);
     hwpf.Read1b(&outline, 1);
     hwpf.Read1b(&outline_continue, 1);
diff --git a/hwpfilter/source/hinfo.h b/hwpfilter/source/hinfo.h
index 590b5f962e7c..21073f07de51 100644
--- a/hwpfilter/source/hinfo.h
+++ b/hwpfilter/source/hinfo.h
@@ -292,7 +292,7 @@ struct ParaShape
     unsigned char condense;
     unsigned char arrange_type;
     TabSet    tabs[MAXTABS];
-    ColumnDef coldef;
+    std::shared_ptr<ColumnDef> xColdef;
     unsigned char shade;
     unsigned char outline;
     unsigned char outline_continue;
diff --git a/hwpfilter/source/hpara.cxx b/hwpfilter/source/hpara.cxx
index 397a24f84a16..93e51c4fa87c 100644
--- a/hwpfilter/source/hpara.cxx
+++ b/hwpfilter/source/hpara.cxx
@@ -122,8 +122,8 @@ bool HWPPara::Read(HWPFile & hwpf, unsigned char flag)
     }
 
     if (nch && !reuse_shape){
-         if( pshape->coldef.ncols > 1 ) {
-             hwpf.SetColumnDef(&(pshape->coldef));
+         if( pshape->xColdef->ncols > 1 ) {
+             hwpf.SetColumnDef(pshape->xColdef);
          }
     }
 
diff --git a/hwpfilter/source/hwpfile.cxx b/hwpfilter/source/hwpfile.cxx
index 00c45475fdf1..0aa1e9541af0 100644
--- a/hwpfilter/source/hwpfile.cxx
+++ b/hwpfilter/source/hwpfile.cxx
@@ -407,7 +407,7 @@ ColumnDef *HWPFile::GetColumnDef(int num)
     }
 
     if( it != columnlist.end() )
-        return (*it)->coldef;
+        return (*it)->xColdef.get();
     else
         return nullptr;
 }
@@ -571,12 +571,12 @@ void HWPFile::AddColumnInfo()
     setMaxSettedPage();
 }
 
-void HWPFile::SetColumnDef(ColumnDef *coldef)
+void HWPFile::SetColumnDef(std::shared_ptr<ColumnDef>& rColdef)
 {
     ColumnInfo *cinfo = columnlist.back();
     if( cinfo->bIsSet )
         return;
-    cinfo->coldef = coldef;
+    cinfo->xColdef = rColdef;
     cinfo->bIsSet = true;
 }
 
diff --git a/hwpfilter/source/hwpfile.h b/hwpfilter/source/hwpfile.h
index 3fab3a5b3dd4..c98f90c82fe2 100644
--- a/hwpfilter/source/hwpfile.h
+++ b/hwpfilter/source/hwpfile.h
@@ -70,11 +70,10 @@ class   HStream;
 struct ColumnInfo{
     int start_page;
     bool bIsSet;
-    ColumnDef *coldef;
+    std::shared_ptr<ColumnDef> xColdef;
     explicit ColumnInfo(int num){
         start_page = num;
         bIsSet = false;
-        coldef = nullptr;
     }
 };
 
@@ -211,7 +210,7 @@ class DLLEXPORT HWPFile
         void AddBox(FBox *);
         void AddPage(){ m_nCurrentPage++;}
         void AddColumnInfo();
-        void SetColumnDef(ColumnDef *coldef);
+        void SetColumnDef(std::shared_ptr<ColumnDef>&);
         void AddParaShape(std::shared_ptr<ParaShape>&);
         void AddCharShape(std::shared_ptr<CharShape>&);
         void AddFBoxStyle(FBoxStyle *);
commit bdf30af5c2323e6f84e4bea8c7fbbcafa1dc91b3
Author: Caolán McNamara <caolanm at redhat.com>
Date:   Sat Feb 24 19:25:01 2018 +0000

    forcepoint #7 check ksc5601_2uni_page21 bounds
    
    Change-Id: I578e7a63bb50f2088d35174d88f075c00469bad3
    Reviewed-on: https://gerrit.libreoffice.org/50287
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Miklos Vajna <vmiklos at collabora.co.uk>

diff --git a/hwpfilter/source/hcode.cxx b/hwpfilter/source/hcode.cxx
index d2eaf57bd28f..2e4bae750e67 100644
--- a/hwpfilter/source/hcode.cxx
+++ b/hwpfilter/source/hcode.cxx
@@ -1139,14 +1139,11 @@ int kssm_hangul_to_ucs2(hchar ch, hchar *dest)
 hchar ksc5601_sym_to_ucs2 (hchar input)
 {
     unsigned char ch = sal::static_int_cast<unsigned char>(input >> 8);
-    unsigned char ch2;
-    int idx;
-
-    ch2 = sal::static_int_cast<unsigned char>(input & 0xff);
-    idx = (ch - 0xA1) * 94 + (ch2 - 0xA1);
-    if (idx <= 1114 && idx >= 0){
-    hchar value = ksc5601_2uni_page21[idx];
-    return value ? value :  0x25a1;
+    unsigned char ch2 = sal::static_int_cast<unsigned char>(input & 0xff);
+    int idx = (ch - 0xA1) * 94 + (ch2 - 0xA1);
+    if (idx >= 0 && idx < static_cast<int>(SAL_N_ELEMENTS(ksc5601_2uni_page21))) {
+        hchar value = ksc5601_2uni_page21[idx];
+        return value ? value :  0x25a1;
     }
     return 0x25a1;
 }
@@ -1154,15 +1151,12 @@ hchar ksc5601_sym_to_ucs2 (hchar input)
 hchar ksc5601_han_to_ucs2 (hchar input)
 {
     unsigned char ch = sal::static_int_cast<unsigned char>(input >> 8);
-    unsigned char ch2;
-    int idx;
-
-    ch2 = sal::static_int_cast<unsigned char>(input & 0xff);
-    idx = (ch - 0xA1) * 94 + (ch2 - 0xA1);
-    if (idx >= 3854){
-    // Hanja : row 42 - row 93 : 3854 = 94 * (42-1)
-    hchar value = ksc5601_2uni_page21[idx - 3854];
-    return value ? value : '?';
+    unsigned char ch2 = sal::static_int_cast<unsigned char>(input & 0xff);
+    int idx = (ch - 0xA1) * 94 + (ch2 - 0xA1);
+    if (idx >= 3854 && idx < static_cast<int>(3854 + SAL_N_ELEMENTS(ksc5601_2uni_page21))) {
+        // Hanja : row 42 - row 93 : 3854 = 94 * (42-1)
+        hchar value = ksc5601_2uni_page21[idx - 3854];
+        return value ? value : '?';
     }
     return '?';
 }


More information about the Libreoffice-commits mailing list