summaryrefslogtreecommitdiff
path: root/sc/source/core/data/fillinfo.cxx
diff options
context:
space:
mode:
authorStephan Bergmann <sbergman@redhat.com>2019-05-31 14:39:51 +0200
committerStephan Bergmann <sbergman@redhat.com>2019-05-31 18:36:56 +0200
commit7af481139c27baa18e16030921d6c8ebe8b9fe25 (patch)
treef998b7e07e530a6fd355b7f49b9d956da014ed66 /sc/source/core/data/fillinfo.cxx
parent77ae0abe21f672cf4b7d2e069f1d40d20edc49a7 (diff)
Avoid overflow when scaling column width
With -fsanitize=float-cast-overflow, `--convert-to pdf csv/fdo40053-1.csv` with csv/fdo40053-1.csv as obtained by bin/get-bugzilla-attachments-by-mimetype (i.e., the attachment at <https://bugs.documentfoundation.org/show_bug.cgi?id=40053#c0>) fails with > sc/source/core/data/fillinfo.cxx:445:65: runtime error: 88326.7 is outside the range of representable values of type 'unsigned short' > #0 in ScDocument::FillInfo(ScTableInfo&, short, int, short, int, short, double, double, bool, bool, ScMarkData const*) at sc/source/core/data/fillinfo.cxx:445:65 (instdir/program/../program/libsclo.so +0xdb7913d) > #1 in ScPrintFunc::PrintArea(short, int, short, int, long, long, bool, bool, bool, bool) at sc/source/ui/view/printfun.cxx:1597:11 (instdir/program/../program/libsclo.so +0x130c0f91) > #2 in ScPrintFunc::PrintPage(long, short, int, short, int, bool, ScPreviewLocationData*) at sc/source/ui/view/printfun.cxx:2284:9 (instdir/program/../program/libsclo.so +0x130dbf41) > #3 in ScPrintFunc::DoPrint(MultiSelection const&, long, long, bool, ScPreviewLocationData*) at sc/source/ui/view/printfun.cxx:2702:29 (instdir/program/../program/libsclo.so +0x130e8cde) > #4 in ScModelObj::render(int, com::sun::star::uno::Any const&, com::sun::star::uno::Sequence<com::sun::star::beans::PropertyValue> const&) at sc/source/ui/unoobj/docuno.cxx:2064:23 (instdir/program/../program/libsclo.so +0x124fea63) > #5 in PDFExport::ExportSelection(vcl::PDFWriter&, com::sun::star::uno::Reference<com::sun::star::view::XRenderable> const&, com::sun::star::uno::Any const&, StringRangeEnumerator const&, com::sun::star::uno::Sequence<com::sun::star::beans::PropertyValue>&, int) at filter/source/pdf/pdfexport.cxx:227:34 (instdir/program/../program/libpdffilterlo.so +0x2db3b6) > #6 in PDFExport::Export(rtl::OUString const&, com::sun::star::uno::Sequence<com::sun::star::beans::PropertyValue> const&) at filter/source/pdf/pdfexport.cxx:939:28 (instdir/program/../program/libpdffilterlo.so +0x2f3751) > #7 in PDFFilter::implExport(com::sun::star::uno::Sequence<com::sun::star::beans::PropertyValue> const&) at filter/source/pdf/pdffilter.cxx:155:24 (instdir/program/../program/libpdffilterlo.so +0x33d7df) > #8 in PDFFilter::filter(com::sun::star::uno::Sequence<com::sun::star::beans::PropertyValue> const&) at filter/source/pdf/pdffilter.cxx:216:23 (instdir/program/../program/libpdffilterlo.so +0x33e64f) > #9 in SfxObjectShell::ExportTo(SfxMedium&) at sfx2/source/doc/objstor.cxx:2422:25 (instdir/program/libsfxlo.so +0x4a03623) [...] where nX = 2, nTab = 0, GetColWidth(0,2) = 50075, and fColScale = 1.76389. Given csv/fdo40053-1.csv has rather much text in the third column, these values do not look completely implausible (whatever the column width unit of measure is, though)---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. (Using std::clamp, we can get rid of the following lines that ensure nThisWidth >= 1.) Change-Id: Ifa7a666abedc2a2f0a335f4da0ea74961f33870c Reviewed-on: https://gerrit.libreoffice.org/73267 Tested-by: Jenkins Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
Diffstat (limited to 'sc/source/core/data/fillinfo.cxx')
-rw-r--r--sc/source/core/data/fillinfo.cxx6
1 files changed, 3 insertions, 3 deletions
diff --git a/sc/source/core/data/fillinfo.cxx b/sc/source/core/data/fillinfo.cxx
index 63055bdb11b2..abe95752ff68 100644
--- a/sc/source/core/data/fillinfo.cxx
+++ b/sc/source/core/data/fillinfo.cxx
@@ -40,6 +40,8 @@
#include <cellvalue.hxx>
#include <mtvcellfunc.hxx>
+#include <algorithm>
+#include <limits>
#include <vector>
#include <memory>
@@ -442,9 +444,7 @@ void ScDocument::FillInfo(
// TODO: Optimize this loop.
if (!ColHidden(nX, nTab))
{
- sal_uInt16 nThisWidth = static_cast<sal_uInt16>(GetColWidth( nX, nTab ) * fColScale);
- if (!nThisWidth)
- nThisWidth = 1;
+ sal_uInt16 nThisWidth = static_cast<sal_uInt16>(std::clamp(GetColWidth( nX, nTab ) * fColScale, 1.0, double(std::numeric_limits<sal_uInt16>::max())));
pRowInfo[0].pCellInfo[nArrCol].nWidth = nThisWidth; //TODO: this should be enough