diff options
author | Eike Rathke <erack@redhat.com> | 2017-11-03 21:13:12 +0100 |
---|---|---|
committer | Eike Rathke <erack@redhat.com> | 2017-11-03 23:37:54 +0100 |
commit | b00c6912a4f3ba417551d98f4d2a70c4e2328718 (patch) | |
tree | 2d596af04ba7bcc8403522a39c4a324db5c1dee4 /sc/source | |
parent | 2e39e519767d58a20829baca2fb0a2418b70f772 (diff) |
ofz#3032 skip invalid positioned formulas entirely
... instead of generating them at the outer edge, specifically do
not create maximally dimensioned but still truncated matrix
formulas. Carried over-edge cases even overwrote each other
anyway.
Change-Id: Icb307f17ad153c6a5c69f869026abc1cf1d5c9f5
Diffstat (limited to 'sc/source')
-rw-r--r-- | sc/source/ui/docshell/impex.cxx | 27 |
1 files changed, 24 insertions, 3 deletions
diff --git a/sc/source/ui/docshell/impex.cxx b/sc/source/ui/docshell/impex.cxx index 6aa1e4c1dfa2..911c8ea584b0 100644 --- a/sc/source/ui/docshell/impex.cxx +++ b/sc/source/ui/docshell/impex.cxx @@ -1740,6 +1740,10 @@ bool ScImportExport::Sylk2Doc( SvStream& rStrm ) aLine = OStringToOUString(aByteLine, rStrm.GetStreamCharSet()); if( rStrm.IsEof() ) break; + bool bInvalidCol = false; + bool bInvalidRow = false; + bool bInvalidRefCol = false; + bool bInvalidRefRow = false; const sal_Unicode* p = aLine.getStr(); sal_Unicode cTag = *p++; if( cTag == 'C' ) // Content @@ -1754,41 +1758,49 @@ bool ScImportExport::Sylk2Doc( SvStream& rStrm ) { case 'X': { + bInvalidCol = false; bool bFail = o3tl::checked_add<SCCOL>(OUString(p).toInt32(), nStartCol - 1, nCol); if (bFail || nCol < 0 || MAXCOL < nCol) { SAL_WARN("sc.ui","ScImportExport::Sylk2Doc - ;X invalid nCol=" << nCol); nCol = std::max<SCCOL>(0, std::min<SCCOL>(nCol, MAXCOL)); + bInvalidCol = true; } break; } case 'Y': { + bInvalidRow = false; bool bFail = o3tl::checked_add(OUString(p).toInt32(), nStartRow - 1, nRow); if (bFail || nRow < 0 || MAXROW < nRow) { SAL_WARN("sc.ui","ScImportExport::Sylk2Doc - ;Y invalid nRow=" << nRow); nRow = std::max<SCROW>(0, std::min<SCROW>(nRow, MAXROW)); + bInvalidRow = true; } break; } case 'C': { + bInvalidRefCol = false; bool bFail = o3tl::checked_add<SCCOL>(OUString(p).toInt32(), nStartCol - 1, nRefCol); if (bFail || nRefCol < 0 || MAXCOL < nRefCol) { SAL_WARN("sc.ui","ScImportExport::Sylk2Doc - ;C invalid nRefCol=" << nRefCol); nRefCol = std::max<SCCOL>(0, std::min<SCCOL>(nRefCol, MAXCOL)); + bInvalidRefCol = true; } break; } case 'R': { + bInvalidRefRow = false; bool bFail = o3tl::checked_add(OUString(p).toInt32(), nStartRow - 1, nRefRow); if (bFail || nRefRow < 0 || MAXROW < nRefRow) { SAL_WARN("sc.ui","ScImportExport::Sylk2Doc - ;R invalid nRefRow=" << nRefRow); nRefRow = std::max<SCROW>(0, std::min<SCROW>(nRefRow, MAXROW)); + bInvalidRefRow = true; } break; } @@ -1797,7 +1809,8 @@ bool ScImportExport::Sylk2Doc( SvStream& rStrm ) if( !bSingle && ( nCol < nStartCol || nCol > nEndCol || nRow < nStartRow || nRow > nEndRow - || nCol > MAXCOL || nRow > MAXROW ) ) + || nCol > MAXCOL || nRow > MAXROW + || bInvalidCol || bInvalidRow ) ) break; if( !bData ) { @@ -1819,7 +1832,7 @@ bool ScImportExport::Sylk2Doc( SvStream& rStrm ) const sal_Unicode* q = p; while( *q && *q != ';' ) q++; - if ( !(*q == ';' && *(q+1) == 'I') ) + if ( !(*q == ';' && *(q+1) == 'I') && !bInvalidCol && !bInvalidRow ) { // don't ignore value if( bText ) { @@ -1858,6 +1871,10 @@ bool ScImportExport::Sylk2Doc( SvStream& rStrm ) break; aText = "="; p = lcl_ScanSylkFormula( p, aText, eVersion); + + if (bInvalidCol || bInvalidRow || (ch == 'M' && (bInvalidRefCol || bInvalidRefRow))) + break; + ScAddress aPos( nCol, nRow, aRange.aStart.Tab() ); /* FIXME: do we want GRAM_ODFF_A1 instead? At the * end it probably should be GRAM_ODFF_R1C1, since @@ -1902,21 +1919,25 @@ bool ScImportExport::Sylk2Doc( SvStream& rStrm ) { case 'X': { + bInvalidCol = false; bool bFail = o3tl::checked_add<SCCOL>(OUString(p).toInt32(), nStartCol - 1, nCol); if (bFail || nCol < 0 || MAXCOL < nCol) { SAL_WARN("sc.ui","ScImportExport::Sylk2Doc - ;X invalid nCol=" << nCol); nCol = std::max<SCCOL>(0, std::min<SCCOL>(nCol, MAXCOL)); + bInvalidCol = true; } break; } case 'Y': { + bInvalidRow = false; bool bFail = o3tl::checked_add(OUString(p).toInt32(), nStartRow - 1, nRow); if (bFail || nRow < 0 || MAXROW < nRow) { SAL_WARN("sc.ui","ScImportExport::Sylk2Doc - ;Y invalid nRow=" << nRow); nRow = std::max<SCROW>(0, std::min<SCROW>(nRow, MAXROW)); + bInvalidRow = true; } break; } @@ -1946,7 +1967,7 @@ bool ScImportExport::Sylk2Doc( SvStream& rStrm ) if( nCol > nEndCol ) nEndCol = nCol; } - if ( 0 <= nFormat && nFormat < (sal_Int32)aFormats.size() ) + if ( 0 <= nFormat && nFormat < (sal_Int32)aFormats.size() && !bInvalidCol && !bInvalidRow ) { sal_uInt32 nKey = aFormats[nFormat]; pDoc->ApplyAttr( nCol, nRow, aRange.aStart.Tab(), |