[Libreoffice-commits] core.git: emfio/source
Caolán McNamara (via logerrit)
logerrit at kemper.freedesktop.org
Sat Feb 27 19:15:46 UTC 2021
emfio/source/reader/mtftools.cxx | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
New commits:
commit 28e022c258682dc030668fed7879d9d3f078b720
Author: Caolán McNamara <caolanm at redhat.com>
AuthorDate: Thu Feb 25 20:23:33 2021 +0000
Commit: Caolán McNamara <caolanm at redhat.com>
CommitDate: Sat Feb 27 20:15:02 2021 +0100
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 at redhat.com>
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));
More information about the Libreoffice-commits
mailing list