sc/source/ui/docshell/docsh.cxx | 14 ++++++++++++++ sc/source/ui/docshell/impex.cxx | 27 ++++++++++++++++++++++++--- 2 files changed, 38 insertions(+), 3 deletions(-)
New commits: commit 12f09377b91b6d70efb3448d098f4dbd677a67d1 Author: Eike Rathke <er...@redhat.com> Date: Fri Nov 3 23:10:01 2017 +0100 SYLK import: set and evaluate col/row overflow to display dialog Change-Id: Id997aac2fd90f53652c81884c51833c92494e32f diff --git a/sc/source/ui/docshell/docsh.cxx b/sc/source/ui/docshell/docsh.cxx index a9faf61da2b6..f9d2cc684d91 100644 --- a/sc/source/ui/docshell/docsh.cxx +++ b/sc/source/ui/docshell/docsh.cxx @@ -1345,6 +1345,8 @@ bool ScDocShell::ConvertFrom( SfxMedium& rMedium ) else if (aFltName == pFilterSylk) { ErrCode eError = SCERR_IMPORT_UNKNOWN; + bool bOverflowRow, bOverflowCol, bOverflowCell; + bOverflowRow = bOverflowCol = bOverflowCell = false; if( !rMedium.IsStorage() ) { ScImportExport aImpEx( &aDocument ); @@ -1358,6 +1360,10 @@ bool ScDocShell::ConvertFrom( SfxMedium& rMedium ) aDocument.StartAllListeners(); sc::SetFormulaDirtyContext aCxt; aDocument.SetAllFormulasDirty(aCxt); + + bOverflowRow = aImpEx.IsOverflowRow(); + bOverflowCol = aImpEx.IsOverflowCol(); + bOverflowCell = aImpEx.IsOverflowCell(); } else { @@ -1367,6 +1373,14 @@ bool ScDocShell::ConvertFrom( SfxMedium& rMedium ) if ( eError != ERRCODE_NONE && !GetError() ) SetError(eError); + else if (!GetError() && (bOverflowRow || bOverflowCol || bOverflowCell)) + { + // precedence: row, column, cell + ErrCode nWarn = (bOverflowRow ? SCWARN_IMPORT_ROW_OVERFLOW : + (bOverflowCol ? SCWARN_IMPORT_COLUMN_OVERFLOW : + SCWARN_IMPORT_CELL_OVERFLOW)); + SetError(nWarn); + } bSetColWidths = true; bSetSimpleTextColWidths = true; bSetRowHeights = true; diff --git a/sc/source/ui/docshell/impex.cxx b/sc/source/ui/docshell/impex.cxx index 911c8ea584b0..953956213faa 100644 --- a/sc/source/ui/docshell/impex.cxx +++ b/sc/source/ui/docshell/impex.cxx @@ -1764,7 +1764,7 @@ bool ScImportExport::Sylk2Doc( SvStream& rStrm ) { SAL_WARN("sc.ui","ScImportExport::Sylk2Doc - ;X invalid nCol=" << nCol); nCol = std::max<SCCOL>(0, std::min<SCCOL>(nCol, MAXCOL)); - bInvalidCol = true; + bInvalidCol = bOverflowCol = true; } break; } @@ -1776,7 +1776,7 @@ bool ScImportExport::Sylk2Doc( SvStream& rStrm ) { SAL_WARN("sc.ui","ScImportExport::Sylk2Doc - ;Y invalid nRow=" << nRow); nRow = std::max<SCROW>(0, std::min<SCROW>(nRow, MAXROW)); - bInvalidRow = true; + bInvalidRow = bOverflowRow = true; } break; } @@ -1788,7 +1788,7 @@ bool ScImportExport::Sylk2Doc( SvStream& rStrm ) { SAL_WARN("sc.ui","ScImportExport::Sylk2Doc - ;C invalid nRefCol=" << nRefCol); nRefCol = std::max<SCCOL>(0, std::min<SCCOL>(nRefCol, MAXCOL)); - bInvalidRefCol = true; + bInvalidRefCol = bOverflowCol = true; } break; } @@ -1800,7 +1800,7 @@ bool ScImportExport::Sylk2Doc( SvStream& rStrm ) { SAL_WARN("sc.ui","ScImportExport::Sylk2Doc - ;R invalid nRefRow=" << nRefRow); nRefRow = std::max<SCROW>(0, std::min<SCROW>(nRefRow, MAXROW)); - bInvalidRefRow = true; + bInvalidRefRow = bOverflowRow = true; } break; } @@ -1925,7 +1925,7 @@ bool ScImportExport::Sylk2Doc( SvStream& rStrm ) { SAL_WARN("sc.ui","ScImportExport::Sylk2Doc - ;X invalid nCol=" << nCol); nCol = std::max<SCCOL>(0, std::min<SCCOL>(nCol, MAXCOL)); - bInvalidCol = true; + bInvalidCol = bOverflowCol = true; } break; } @@ -1937,7 +1937,7 @@ bool ScImportExport::Sylk2Doc( SvStream& rStrm ) { SAL_WARN("sc.ui","ScImportExport::Sylk2Doc - ;Y invalid nRow=" << nRow); nRow = std::max<SCROW>(0, std::min<SCROW>(nRow, MAXROW)); - bInvalidRow = true; + bInvalidRow = bOverflowRow = true; } break; } commit b00c6912a4f3ba417551d98f4d2a70c4e2328718 Author: Eike Rathke <er...@redhat.com> Date: Fri Nov 3 21:13:12 2017 +0100 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 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(), _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits