diff options
author | Michael Stahl <mst@openoffice.org> | 2012-07-24 11:36:17 +0200 |
---|---|---|
committer | Miklos Vajna <vmiklos@suse.cz> | 2012-07-24 11:37:41 +0200 |
commit | 5a243f140975167aa5c42c95b30edb1cdb1ea639 (patch) | |
tree | d0f3d0512c06692c7e818cf20288e2514e4c736b /hwpfilter/source/hwpread.cxx | |
parent | e5762c8488e233ac7de394d631202d452b1c92a4 (diff) |
hwpfilter: improve text import and error handling
Change-Id: Ib74b96200c9d57f55fc0d32b638601c64e7eb6fe
Diffstat (limited to 'hwpfilter/source/hwpread.cxx')
-rw-r--r-- | hwpfilter/source/hwpread.cxx | 41 |
1 files changed, 31 insertions, 10 deletions
diff --git a/hwpfilter/source/hwpread.cxx b/hwpfilter/source/hwpread.cxx index 557457fa0f9b..325f74c5d358 100644 --- a/hwpfilter/source/hwpread.cxx +++ b/hwpfilter/source/hwpread.cxx @@ -19,6 +19,8 @@ #include "precompile.h" +#include <comphelper/newarray.hxx> + #include <list> #include "hwpfile.h" @@ -77,20 +79,30 @@ int FieldCode::Read(HWPFile & hwpf) hwpf.Read4b(&len3, 1); hwpf.Read4b(&binlen, 1); - str1 = new hchar[len1]; - str2 = new hchar[len2]; - str3 = new hchar[len3]; + ulong const len1_ = ((len1 > 1024) ? 1024 : len1) / sizeof(hchar); + ulong const len2_ = ((len2 > 1024) ? 1024 : len2) / sizeof(hchar); + ulong const len3_ = ((len3 > 1024) ? 1024 : len3) / sizeof(hchar); + + str1 = new hchar[len1_ ? len1_ : 1]; + str2 = new hchar[len2_ ? len2_ : 1]; + str3 = new hchar[len3_ ? len3_ : 1]; bin = new char[binlen]; - hwpf.Read2b(str1, len1/2); - hwpf.Read2b(str2, len2/2); - hwpf.Read2b(str3, len3/2); + hwpf.Read2b(str1, len1_); + hwpf.SkipBlock(len1 - (len1_ * sizeof(hchar))); + str1[len1_ ? (len1_ - 1) : 0] = 0; + hwpf.Read2b(str2, len2_); + hwpf.SkipBlock(len2 - (len2_ * sizeof(hchar))); + str2[len2_ ? (len2_ - 1) : 0] = 0; + hwpf.Read2b(str3, len3_); + hwpf.SkipBlock(len3 - (len3_ * sizeof(hchar))); + str3[len3_ ? (len3_ - 1) : 0] = 0; hwpf.ReadBlock(bin, binlen); if( type[0] == 3 && type[1] == 2 ){ /* 糯¥μ ؾ Ѵ. */ DateCode *pDate = new DateCode; - for( int i = 0 ;i < (int)(len3/2) ; i++ ){ + for (int i = 0 ; i < static_cast<int>(len3_); i++) { if(str3[i] == 0 ) break; if( i >= DATE_SIZE ) break; pDate->format[i] = str3[i]; @@ -277,7 +289,10 @@ int TxtBox::Read(HWPFile & hwpf) return hwpf.SetState(HWP_InvalidFileFormat); } - cell = new Cell[ncell]; + cell = ::comphelper::newArray_null<Cell>(ncell); + if (!cell) { + return hwpf.SetState(HWP_InvalidFileFormat); + } for (ii = 0; ii < ncell; ii++) { cell[ii].Read(hwpf); @@ -285,7 +300,10 @@ int TxtBox::Read(HWPFile & hwpf) } if (ncell == 1) style.cell = &cell[0]; - plists = new std::list < HWPPara* >[ncell]; + plists = ::comphelper::newArray_null< std::list< HWPPara* > >(ncell); + if (!plists) { + return hwpf.SetState(HWP_InvalidFileFormat); + } for (ii = 0; ii < ncell; ii++) hwpf.ReadParaList(plists[ii]); // caption @@ -300,7 +318,10 @@ int TxtBox::Read(HWPFile & hwpf) tbl->rows.insert(cell[ii].y); tbl->rows.insert(cell[ii].y + cell[ii].h); } - TCell* *pArr = new TCell*[ncell]; + TCell* *pArr = ::comphelper::newArray_null<TCell *>(ncell); + if (!pArr) { + return hwpf.SetState(HWP_InvalidFileFormat); + } for( ii = 0 ; ii < ncell; ii++) { TCell *tcell = new TCell; |