summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJustin Luth <justin.luth@collabora.com>2021-04-06 16:40:25 +0200
committerXisco Fauli <xiscofauli@libreoffice.org>2021-04-09 14:47:01 +0200
commita159d7d2db7a86c770a165b04999f3ab513d3127 (patch)
tree31f95f05dd0ca39d6af9375ef4ff4bd726470a57
parenttdf#141529 sync linked OLE save(s) with hosting file save(s) (diff)
downloadcore-a159d7d2db7a86c770a165b04999f3ab513d3127.tar.gz
core-a159d7d2db7a86c770a165b04999f3ab513d3127.zip
tdf#139495 doc import: prevent negative Int forced into uInt
Don't cast a negative number into a sal_uInt16 and expect good results. (ww8import test) But for bug 139495 (and ww8export3), the problem area is also related to pHdFormat->SetFormatAttr(SwFormatFrameSize... which takes an awt::Size which consists of Longs. So they should accept negative numbers. Likely the result is being treated as a uInt somewhere. And a negative height doesn't mean very much anyway. There seems to be a fundamental difference between Word and LO here. Word sets the page margins, but that is irrelevant to the header/footer, which have their own distance from the edge. In LO, the header starts at the page margin, and the body text must follow the header, (In Word, the body text can start above the header, as seen in the ww8export3 unit test.) [FYI: DOC format (since forever) seems to ignore the header size, allowing the content to at least overlap with the body text, but DOCX doesn't have that. Likely this is #112727# using floating frames hack. So I'd better not keep messing around in here.] Change-Id: Ie7bffec8a3de25958cf1f311ff2c8338d4870d99 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/113681 Tested-by: Jenkins Reviewed-by: Justin Luth <justin_luth@sil.org> (cherry picked from commit 28a9a92105f3155d82fd9e31095efabd3ec706ea) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/113769 Reviewed-by: Xisco Fauli <xiscofauli@libreoffice.org>
-rw-r--r--sw/qa/extras/ww8export/data/tdf139495_tinyHeader.docbin0 -> 22016 bytes
-rw-r--r--sw/qa/extras/ww8export/ww8export3.cxx6
-rw-r--r--sw/qa/extras/ww8import/ww8import.cxx4
-rw-r--r--sw/source/filter/ww8/ww8par6.cxx6
4 files changed, 14 insertions, 2 deletions
diff --git a/sw/qa/extras/ww8export/data/tdf139495_tinyHeader.doc b/sw/qa/extras/ww8export/data/tdf139495_tinyHeader.doc
new file mode 100644
index 000000000000..c45a6c25fd99
--- /dev/null
+++ b/sw/qa/extras/ww8export/data/tdf139495_tinyHeader.doc
Binary files differ
diff --git a/sw/qa/extras/ww8export/ww8export3.cxx b/sw/qa/extras/ww8export/ww8export3.cxx
index dd7de5ff543a..c16272c2707d 100644
--- a/sw/qa/extras/ww8export/ww8export3.cxx
+++ b/sw/qa/extras/ww8export/ww8export3.cxx
@@ -202,6 +202,12 @@ DECLARE_WW8EXPORT_TEST(testTdf122460_header, "tdf122460_header.odt")
CPPUNIT_ASSERT(headerIsOn);
}
+DECLARE_WW8EXPORT_TEST(testTdf139495_tinyHeader, "tdf139495_tinyHeader.doc")
+{
+ // In Word 2003, this is one page, but definitely not six pages.
+ CPPUNIT_ASSERT(getPages() < 3);
+}
+
DECLARE_WW8EXPORT_TEST(testFdo53985, "fdo53985.doc")
{
uno::Reference<text::XTextTablesSupplier> xTablesSupplier(mxComponent, uno::UNO_QUERY);
diff --git a/sw/qa/extras/ww8import/ww8import.cxx b/sw/qa/extras/ww8import/ww8import.cxx
index 9cbae7f83a3a..0698c9578fa8 100644
--- a/sw/qa/extras/ww8import/ww8import.cxx
+++ b/sw/qa/extras/ww8import/ww8import.cxx
@@ -246,6 +246,10 @@ DECLARE_WW8IMPORT_TEST(testTdf122425_1, "tdf122425_1.doc")
CPPUNIT_ASSERT(!pBox->GetLine(eLine));
}
}
+
+ //tdf#139495: without the fix, a negative number was converted into a uInt16, overflowing to 115501
+ auto nDist = getProperty<sal_uInt32>(getStyles("PageStyles")->getByName("Standard"), "HeaderBodyDistance");
+ CPPUNIT_ASSERT_EQUAL(sal_uInt32(0), nDist);
}
DECLARE_WW8IMPORT_TEST(testTdf110987, "tdf110987")
diff --git a/sw/source/filter/ww8/ww8par6.cxx b/sw/source/filter/ww8/ww8par6.cxx
index adbfaf20bae3..ec87b0abc1b6 100644
--- a/sw/source/filter/ww8/ww8par6.cxx
+++ b/sw/source/filter/ww8/ww8par6.cxx
@@ -661,8 +661,10 @@ void wwSectionManager::SetPageULSpaceItems(SwFrameFormat &rFormat,
}
else
{
+ // Hack alert: these calculations are based on
+ // #112727# import negative height headers/footers as floating frames inside fixed height headers/footer
// #i48832# - set correct spacing between header and body.
- const sal_Int32 nHdLowerSpace( std::abs(rSection.maSep.dyaTop) - rData.nSwUp - rData.nSwHLo );
+ const sal_Int32 nHdLowerSpace(std::max<sal_Int32>(0, std::abs(rSection.maSep.dyaTop) - rData.nSwUp - rData.nSwHLo));
pHdFormat->SetFormatAttr(SwFormatFrameSize(SwFrameSize::Fixed, 0, rData.nSwHLo + nHdLowerSpace));
aHdUL.SetLower( static_cast< sal_uInt16 >(nHdLowerSpace) );
pHdFormat->SetFormatAttr(SwHeaderAndFooterEatSpacingItem(
@@ -689,7 +691,7 @@ void wwSectionManager::SetPageULSpaceItems(SwFrameFormat &rFormat,
else
{
// #i48832# - set correct spacing between footer and body.
- const SwTwips nFtUpperSpace( std::abs(rSection.maSep.dyaBottom) - rData.nSwLo - rData.nSwFUp );
+ const sal_Int32 nFtUpperSpace(std::max<sal_Int32>(0, std::abs(rSection.maSep.dyaBottom) - rData.nSwLo - rData.nSwFUp));
pFtFormat->SetFormatAttr(SwFormatFrameSize(SwFrameSize::Fixed, 0, rData.nSwFUp + nFtUpperSpace));
aFtUL.SetUpper( static_cast< sal_uInt16 >(nFtUpperSpace) );
pFtFormat->SetFormatAttr(SwHeaderAndFooterEatSpacingItem(