sc/source/ui/docshell/impex.cxx | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-)
New commits: commit 2cb743eea3396541e155c24773b54de0663c7475 Author: Eike Rathke <er...@redhat.com> AuthorDate: Fri Sep 11 20:24:22 2020 +0200 Commit: Eike Rathke <er...@redhat.com> CommitDate: Fri Sep 11 22:05:55 2020 +0200 Make arbitrary cell length limit in CSV import a constexpr ... so we could up that in one place if we really wanted. Usually exceeding that length is due to malformed data opening a quoted field without closing it. However, there might be valid reasons to allow more than 64k characters in one cell, but think about a *reasonable* limit, not 2GB ... Change-Id: I7f9ea80ab2f7a4eb34d93203286c973ea03f1ce0 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/102495 Reviewed-by: Eike Rathke <er...@redhat.com> Tested-by: Jenkins diff --git a/sc/source/ui/docshell/impex.cxx b/sc/source/ui/docshell/impex.cxx index 98b65f929346..fbd30d4234d0 100644 --- a/sc/source/ui/docshell/impex.cxx +++ b/sc/source/ui/docshell/impex.cxx @@ -66,10 +66,11 @@ // We don't want to end up with 2GB read in one line just because of malformed // multiline fields, so chop it _somewhere_, which is twice supported columns -// times maximum cell content length, 2*1024*64K=128M, and because it's -// sal_Unicode that's 256MB. If it's 2GB of data without LF we're out of luck -// anyway. -const sal_Int32 nArbitraryLineLengthLimit = 2 * MAXCOLCOUNT * 65536; +// times arbitrary maximum cell content length, 2*1024*64K=128M, and because +// it's sal_Unicode that's 256MB. If it's 2GB of data without LF we're out of +// luck anyway. +constexpr sal_Int32 nArbitraryCellLengthLimit = SAL_MAX_UINT16; +constexpr sal_Int32 nArbitraryLineLengthLimit = 2 * MAXCOLCOUNT * nArbitraryCellLengthLimit; namespace { @@ -632,15 +633,15 @@ static QuoteType lcl_isEscapedOrFieldEndQuote( sal_Int32 nQuotes, const sal_Unic */ static bool lcl_appendLineData( OUString& rField, const sal_Unicode* p1, const sal_Unicode* p2 ) { - OSL_ENSURE( rField.getLength() + (p2 - p1) <= SAL_MAX_UINT16, "lcl_appendLineData: data overflow"); - if (rField.getLength() + (p2 - p1) <= SAL_MAX_UINT16) + if (rField.getLength() + (p2 - p1) <= nArbitraryCellLengthLimit) { rField += OUString( p1, sal::static_int_cast<sal_Int32>( p2 - p1 ) ); return true; } else { - rField += OUString( p1, SAL_MAX_UINT16 - rField.getLength() ); + SAL_WARN( "sc", "lcl_appendLineData: data overflow"); + rField += OUString( p1, nArbitraryCellLengthLimit - rField.getLength() ); return false; } } @@ -1274,26 +1275,26 @@ static OUString lcl_GetFixed( const OUString& rLine, sal_Int32 nStart, sal_Int32 rbIsQuoted = (pStr[nStart] == '"' && pStr[nSpace-1] == '"'); if (rbIsQuoted) { - bool bFits = (nSpace - nStart - 3 <= SAL_MAX_UINT16); - OSL_ENSURE( bFits, "lcl_GetFixed: line doesn't fit into data"); + bool bFits = (nSpace - nStart - 3 <= nArbitraryCellLengthLimit); if (bFits) return rLine.copy(nStart+1, std::max< sal_Int32 >(0, nSpace-nStart-2)); else { + SAL_WARN( "sc", "lcl_GetFixed: line doesn't fit into data"); rbOverflowCell = true; - return rLine.copy(nStart+1, SAL_MAX_UINT16); + return rLine.copy(nStart+1, nArbitraryCellLengthLimit); } } else { - bool bFits = (nSpace - nStart <= SAL_MAX_UINT16); - OSL_ENSURE( bFits, "lcl_GetFixed: line doesn't fit into data"); + bool bFits = (nSpace - nStart <= nArbitraryCellLengthLimit); if (bFits) return rLine.copy(nStart, nSpace-nStart); else { + SAL_WARN( "sc", "lcl_GetFixed: line doesn't fit into data"); rbOverflowCell = true; - return rLine.copy(nStart, SAL_MAX_UINT16); + return rLine.copy(nStart, nArbitraryCellLengthLimit); } } } _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits