sc/source/core/data/column2.cxx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
New commits: commit de4d296619b978ec303f1d7b1e2c78e13fa7a512 Author: Stephan Bergmann <[email protected]> AuthorDate: Fri May 31 15:37:09 2019 +0200 Commit: Stephan Bergmann <[email protected]> CommitDate: Fri May 31 22:27:33 2019 +0200 Avoid overflow in ScColumn::GetOptimalColWidth With -fsanitize=float-cast-overflow, opening csv/fdo40680-1.csv as obtained by bin/get-bugzilla-attachments-by-mimetype (i.e., the attachment at <https://bugs.documentfoundation.org/show_bug.cgi?id=40680#c0>) fails with > sc/source/core/data/column2.cxx:741:53: runtime error: 833163 is outside the range of representable values of type 'unsigned short' > #0 in ScColumn::GetOptimalColWidth(OutputDevice*, double, double, Fraction const&, Fraction const&, bool, unsigned short, ScMarkData const*, ScColWidthParam const*) const at sc/source/core/data/column2.cxx:741:53 (instdir/program/../program/libsclo.so +0xc9374aa) > #1 in ScTable::GetOptimalColWidth(short, OutputDevice*, double, double, Fraction const&, Fraction const&, bool, ScMarkData const*, ScColWidthParam const*) at sc/source/core/data/table1.cxx:427:23 (instdir/program/../program/libsclo.so +0xe02deee) > #2 in ScDocument::GetOptimalColWidth(short, short, OutputDevice*, double, double, Fraction const&, Fraction const&, bool, ScMarkData const*, ScColWidthParam const*) at sc/source/core/data/document.cxx:4242:30 (instdir/program/../program/libsclo.so +0xd18b457) > #3 in ScDocShell::ConvertFrom(SfxMedium&) at sc/source/ui/docshell/docsh.cxx:1614:53 (instdir/program/../program/libsclo.so +0x110b9ad4) > #4 in SfxObjectShell::DoLoad(SfxMedium*) at sfx2/source/doc/objstor.cxx:768:23 (instdir/program/libsfxlo.so +0x49d934a) [...] where nWidth = 5336 and nPPTX = 0.0647688. Given csv/fdo40680-1.csv has rather much text in the 17th column, these values do not look completely implausible ---which of course begs the question whether sal_uInt16 is an appropriate data type here. But assuming sal_uInt16 is a useful choice, just clamp the calculated width accordingly. Change-Id: I9629b45183354d148d572a0850314c9a00548311 Reviewed-on: https://gerrit.libreoffice.org/73273 Reviewed-by: Eike Rathke <[email protected]> Tested-by: Jenkins diff --git a/sc/source/core/data/column2.cxx b/sc/source/core/data/column2.cxx index a4b52eef7061..a29505584a27 100644 --- a/sc/source/core/data/column2.cxx +++ b/sc/source/core/data/column2.cxx @@ -60,6 +60,7 @@ #include <formula/vectortoken.hxx> #include <algorithm> +#include <limits> #include <memory> #include <numeric> @@ -738,7 +739,8 @@ sal_uInt16 ScColumn::GetOptimalColWidth( if (bFound) { nWidth += 2; - sal_uInt16 nTwips = static_cast<sal_uInt16>(nWidth / nPPTX); + sal_uInt16 nTwips = static_cast<sal_uInt16>( + std::min(nWidth / nPPTX, double(std::numeric_limits<sal_uInt16>::max()))); return nTwips; } else _______________________________________________ Libreoffice-commits mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
