vcl/source/gdi/TypeSerializer.cxx | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-)
New commits: commit 32dc2d14287a4210589c33dbd62c6e36e095aa6e Author: Caolán McNamara <caol...@redhat.com> AuthorDate: Fri Mar 18 19:50:12 2022 +0000 Commit: Caolán McNamara <caol...@redhat.com> CommitDate: Sat Mar 19 21:52:01 2022 +0100 ofz#45583 detect some invalid scale cases at import time Change-Id: Iad881f09bef707897e19d402a9931a6dea88f52d Reviewed-on: https://gerrit.libreoffice.org/c/core/+/131839 Tested-by: Jenkins Reviewed-by: Caolán McNamara <caol...@redhat.com> diff --git a/vcl/source/gdi/TypeSerializer.cxx b/vcl/source/gdi/TypeSerializer.cxx index fb054e4748ef..829bc0503e1d 100644 --- a/vcl/source/gdi/TypeSerializer.cxx +++ b/vcl/source/gdi/TypeSerializer.cxx @@ -425,6 +425,22 @@ void TypeSerializer::writeGraphic(const Graphic& rGraphic) } } +static bool UselessScaleForMapMode(const Fraction& rScale) +{ + if (!rScale.IsValid()) + return true; + // ImplLogicToPixel will multiply its values by this numerator * dpi and then double that + // result before dividing + constexpr sal_Int32 nTypicalDPI = 96; + if (rScale.GetNumerator() > std::numeric_limits<sal_Int32>::max() / nTypicalDPI / 2) + return true; + if (rScale.GetNumerator() < std::numeric_limits<sal_Int32>::min() / nTypicalDPI / 2) + return true; + if (static_cast<double>(rScale) < 0.0) + return true; + return false; +} + void TypeSerializer::readMapMode(MapMode& rMapMode) { VersionCompatRead aCompat(mrStream); @@ -441,10 +457,7 @@ void TypeSerializer::readMapMode(MapMode& rMapMode) readFraction(aScaleY); mrStream.ReadCharAsBool(bSimple); - const bool bBogus = !aScaleX.IsValid() || !aScaleY.IsValid() - || aScaleX.GetNumerator() == std::numeric_limits<sal_Int32>::min() - || aScaleY.GetNumerator() == std::numeric_limits<sal_Int32>::min() - || static_cast<double>(aScaleX) < 0.0 || static_cast<double>(aScaleY) < 0.0; + const bool bBogus = UselessScaleForMapMode(aScaleX) || UselessScaleForMapMode(aScaleY); SAL_WARN_IF(bBogus, "vcl", "invalid scale"); if (bSimple || bBogus)