diff options
author | Caolán McNamara <caolanm@redhat.com> | 2021-02-25 20:23:33 +0000 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2021-02-27 20:15:02 +0100 |
commit | 28e022c258682dc030668fed7879d9d3f078b720 (patch) | |
tree | 71215562b7b0d27b4077d694e811f9a7bc7db4a2 /emfio | |
parent | 15b86b9dc15afbb5cc3c318f57f500a6a77b67c9 (diff) |
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>
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 29b31438b399..fdb8496f1563 100644 --- a/emfio/source/reader/mtftools.cxx +++ b/emfio/source/reader/mtftools.cxx @@ -386,10 +386,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 && nMeasuredTextLength) + if (nImportedTextLength != nMeasuredTextLength) { const double fFactorText(static_cast<double>(nImportedTextLength) / static_cast<double>(nMeasuredTextLength)); const double fFactorTextPercent(fabs(1.0 - fFactorText) * 100.0); @@ -418,6 +421,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)); |