Kaydet (Commit) b2aafa91 authored tarafından Michael Stahl's avatar Michael Stahl Kaydeden (comit) Thorsten Behrens

sax: fix overflow in sax::Converter::convertMeasure()

The problem is that -2^31 is negative after negation in 2's
complement.

This causes ODF validation error now in CppunitTest_sd_export_tests
testFdo84043:

Error: attribute "svg:x" has a bad value: ...
svg:x="--2147483.-6-4-7cm"

The validation error only happens in 32-bit builds; 64-bit builds
show a different value svg:x="2139324.72cm", so there must be another
problem somewhere else that isn't fixed here.

Change-Id: If2040cb6ae914c69b7cc651d3ab2d5d232fc71fb
Reviewed-on: https://gerrit.libreoffice.org/56718
Tested-by: Jenkins
Reviewed-by: 's avatarThorsten Behrens <Thorsten.Behrens@CIB.de>
üst be1a2fb3
...@@ -502,6 +502,7 @@ void ConverterTest::testMeasure() ...@@ -502,6 +502,7 @@ void ConverterTest::testMeasure()
doTestMeasureToString("979.928cm", 555550, MeasureUnit::TWIP, MeasureUnit::CM); doTestMeasureToString("979.928cm", 555550, MeasureUnit::TWIP, MeasureUnit::CM);
doTestMeasureToString("111.1pt", 2222, MeasureUnit::TWIP, MeasureUnit::POINT); doTestMeasureToString("111.1pt", 2222, MeasureUnit::TWIP, MeasureUnit::POINT);
doTestMeasureToString("385.7986in", 555550, MeasureUnit::TWIP, MeasureUnit::INCH); doTestMeasureToString("385.7986in", 555550, MeasureUnit::TWIP, MeasureUnit::INCH);
doTestMeasureToString("-2147483.648cm", std::numeric_limits<sal_Int32>::min(), MeasureUnit::MM_100TH, MeasureUnit::CM);
} }
void doTestStringToBool(bool bBool, char const*const pis) void doTestStringToBool(bool bBool, char const*const pis)
......
...@@ -280,10 +280,11 @@ void Converter::convertMeasure( OUStringBuffer& rBuffer, ...@@ -280,10 +280,11 @@ void Converter::convertMeasure( OUStringBuffer& rBuffer,
return; return;
} }
sal_Int64 nValue(nMeasure); // extend to 64-bit first to avoid overflow
// the sign is processed separately // the sign is processed separately
if( nMeasure < 0 ) if (nValue < 0)
{ {
nMeasure = -nMeasure; nValue = -nValue;
rBuffer.append( '-' ); rBuffer.append( '-' );
} }
...@@ -401,7 +402,6 @@ void Converter::convertMeasure( OUStringBuffer& rBuffer, ...@@ -401,7 +402,6 @@ void Converter::convertMeasure( OUStringBuffer& rBuffer,
break; break;
} }
sal_Int64 nValue = nMeasure;
OSL_ENSURE(nValue <= SAL_MAX_INT64 / nMul, "convertMeasure: overflow"); OSL_ENSURE(nValue <= SAL_MAX_INT64 / nMul, "convertMeasure: overflow");
nValue *= nMul; nValue *= nMul;
nValue /= nDiv; nValue /= nDiv;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment