diff options
author | Caolán McNamara <caolanm@redhat.com> | 2021-02-25 15:06:50 +0000 |
---|---|---|
committer | Michael Stahl <michael.stahl@allotropia.de> | 2021-07-08 10:42:56 +0200 |
commit | 3d1e59d9882d1146be303dafff937a51ba4e1867 (patch) | |
tree | 7556399bdeaad2bf261eb620265e5c3e901da6d2 /emfio | |
parent | 81ffcdfe9005bdd78b09e75d06e1a76c24bb9ac6 (diff) |
ofz#31370 Divide-by-zero
Change-Id: If581d61b678616f8a80f8ad2d2dea5ecbf10d8fc
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/111557
Tested-by: Jenkins
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
(cherry picked from commit da457f41f8f0a14014ff9f122467f3a26eb1ac20)
and...
cid#1473321 Division or modulo by float zero
and
cid#1473322 Division or modulo by float zero
where oss-fuzz also found a reproducer as ofz#31370 Divide-by-zero
Change-Id: I0facd2e794384515891dbf040f4fe43530478d3d
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/111601
Tested-by: Jenkins
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
(cherry picked from commit 28e022c258682dc030668fed7879d9d3f078b720)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/118595
Reviewed-by: Michael Stahl <michael.stahl@allotropia.de>
Diffstat (limited to 'emfio')
-rw-r--r-- | emfio/source/reader/mtftools.cxx | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/emfio/source/reader/mtftools.cxx b/emfio/source/reader/mtftools.cxx index 0d918af72dc0..53564c34f82b 100644 --- a/emfio/source/reader/mtftools.cxx +++ b/emfio/source/reader/mtftools.cxx @@ -385,10 +385,13 @@ namespace emfio // calculate measured TextLength const vcl::Font& rFontCandidate(maCurrentMetaFontAction->GetFont()); pTempVirtualDevice->SetFont(rFontCandidate); - const tools::Long nMeasuredTextLength(pTempVirtualDevice->GetTextWidth(rText)); + tools::Long nMeasuredTextLength(pTempVirtualDevice->GetTextWidth(rText)); + // on failure, use original length + if (!nMeasuredTextLength) + nMeasuredTextLength = nImportedTextLength; // compare expected and imported TextLengths - if(nImportedTextLength != nMeasuredTextLength) + if (nImportedTextLength != nMeasuredTextLength) { const double fFactorText(static_cast<double>(nImportedTextLength) / static_cast<double>(nMeasuredTextLength)); const double fFactorTextPercent(fabs(1.0 - fFactorText) * 100.0); @@ -417,6 +420,9 @@ namespace emfio rFontCandidate2.SetAverageFontWidth(static_cast<tools::Long>(fCorrectedAverageFontWidth)); pTempVirtualDevice->SetFont(rFontCandidate2); nCorrectedTextLength = pTempVirtualDevice->GetTextWidth(rText); + // on failure, use original length + if (!nCorrectedTextLength) + nCorrectedTextLength = nImportedTextLength; } const double fFactorCorrectedText(static_cast<double>(nImportedTextLength) / static_cast<double>(nCorrectedTextLength)); |