[Libreoffice-commits] core.git: Branch 'distro/cib/libreoffice-6-1' - 2 commits - sw/source

2019-12-23 Thread Michael Stahl (via logerrit)
 sw/source/core/inc/txtfrm.hxx   |2 ++
 sw/source/core/text/frmform.cxx |9 -
 sw/source/core/text/txtfrm.cxx  |8 
 3 files changed, 14 insertions(+), 5 deletions(-)

New commits:
commit d83f066a8f70e260b388275fe596b37df0ad1eeb
Author: Michael Stahl 
AuthorDate: Fri Dec 20 17:28:55 2019 +0100
Commit: Michael Stahl 
CommitDate: Mon Dec 23 11:26:49 2019 +0100

sw: fix widow loop with as-char flys in text formatting

The document has a paragraph with 4 as-character anchored flys depicting
Zirbenholz; due to their size and an additional fly that is anchored at
the paragraph, there are 3 lines that do not fit onto a single page.

This situation causes a loop that proceeds like this:

text frame 80 is the follow of text frame 21.
when formatting 80:
the 1 line violates the widow rule (>=2) and PREP_WIDOWS is sent to
21, invalidating its FrameAreaSize
80 validates its FrameAreaSize
when formatting 21:
PREP_WIDOWS_ORPHANS sent to 21
CalcPreps() sees IsPrepWidows() and sets a huge height and calls
SetWidow(true)
SwTextFrame::WouldFit() sees IsWidow() true and resets it false
SwTextFrame::WouldFit() sees IsWidow() false and a huge but
insufficiently huge height
21 validates its FrameAreaSize
CalcPreps() sees IsPrepAdjust()
FindBreak() calls TruncLines() and because of as-char fly
invalidates FrameAreaSize of 80

The loop is most easily reproduced by printing via the API; it's
possible to get a loop when loading the document in the UI, but
typically the UI remains responsive even though the layout never
finishes.

As it happens, before commit ee299664940139f6f9543592ece3b3c0210b59f4
"SalInstance::DoYield: Don't drop SolarMutex when accessing user event
queue" the loop on printing via API was broken by releasing SolarMutex;
the result, however, was incorrect, with the last line of Zirbenholz
that should be on the second page missing in the PDF.

This loop is presumably a regression from commit
f2e3655255db4032738849cd4b77ce67a6e2c984 "Avoid
-fsanitize=signed-integer-overflow", which changed a magic number in
SwTextFrame::CalcPreps(), but didn't adapt the poorly documented
corresponding magic numbers in SwTextFrame::WouldFit(); in LO 5.1.6.2
the CPU is idle after loading the document.

Change-Id: Ib6563c21edb68945c14a61b51ba34f0ee3f2544a
Reviewed-on: https://gerrit.libreoffice.org/85623
Tested-by: Jenkins
Reviewed-by: Michael Stahl 
(cherry picked from commit 68a5afaaabd0c75bba3439cfdff90fb75d1cdd3f)

diff --git a/sw/source/core/inc/txtfrm.hxx b/sw/source/core/inc/txtfrm.hxx
index 98a18f7ed8ad..ce5ec49232ed 100644
--- a/sw/source/core/inc/txtfrm.hxx
+++ b/sw/source/core/inc/txtfrm.hxx
@@ -964,6 +964,8 @@ public:
 };
 
 
+const SwTwips WIDOW_MAGIC = (SAL_MAX_INT32 - 1)/2;
+
 } // namespace sw
 
 #endif
diff --git a/sw/source/core/text/frmform.cxx b/sw/source/core/text/frmform.cxx
index 959daa4ea9a1..d5a402ebe4c6 100644
--- a/sw/source/core/text/frmform.cxx
+++ b/sw/source/core/text/frmform.cxx
@@ -849,7 +849,7 @@ bool SwTextFrame::CalcPreps()
 // the range of 'long', while the value (SAL_MAX_INT32 - 
1)/2 (which matches the
 // old value on platforms where 'long' is 'sal_Int32') is 
empirically shown to
 // be large enough in practice even on platforms where 
'long' is 'sal_Int64':
-SwTwips nTmp  = (SAL_MAX_INT32 - 1)/2 - 
(getFrameArea().Top()+1);
+SwTwips const nTmp = sw::WIDOW_MAGIC - 
(getFrameArea().Top()+1);
 SwTwips nDiff = nTmp - getFrameArea().Height();
 
 {
diff --git a/sw/source/core/text/txtfrm.cxx b/sw/source/core/text/txtfrm.cxx
index 62b281ae6974..377dd17c5103 100644
--- a/sw/source/core/text/txtfrm.cxx
+++ b/sw/source/core/text/txtfrm.cxx
@@ -2759,9 +2759,9 @@ bool SwTextFrame::WouldFit( SwTwips &rMaxHeight, bool 
&bSplit, bool bTst )
 // Because the Orphan flag only exists for a short moment, we also check
 // whether the Framesize is set to very huge by CalcPreps, in order to
 // force a MoveFwd
-if( IsWidow() || ( aRectFnSet.IsVert() ?
-   ( 0 == getFrameArea().Left() ) :
-   ( LONG_MAX - 2 < getFrameArea().Bottom() ) ) )
+if (IsWidow() || (aRectFnSet.IsVert()
+? (0 == getFrameArea().Left())
+: (sw::WIDOW_MAGIC - 2 < getFrameArea().Bottom(
 {
 SetWidow(false);
 if ( GetFollow() )
@@ -2770,7 +2770,7 @@ bool SwTextFrame::WouldFit( SwTwips &rMaxHeight, bool 
&bSplit, bool bTst )
 // whether there's a Follow with a real height at all.
 // Else (e.g. for newly created SctFrames) we ignore the IsWidow() 
and
   

[Libreoffice-commits] core.git: Branch 'distro/cib/libreoffice-6-1' - 2 commits - sw/source

2019-10-11 Thread Szymon Kłos (via logerrit)
 sw/source/uibase/dbui/dbmgr.cxx |  746 
 1 file changed, 380 insertions(+), 366 deletions(-)

New commits:
commit 30496b80fd061afe10f6842fe257babb2b2b4bf5
Author: Szymon Kłos 
AuthorDate: Wed Jan 2 19:03:25 2019 +0100
Commit: Samuel Mehrbrodt 
CommitDate: Fri Oct 11 09:42:22 2019 +0200

tdf#117480 fix crash in mailmerge

Catch exceptions and hide progress dialog.

Reviewed-on: https://gerrit.libreoffice.org/65815
Reviewed-by: Szymon Kłos 
Tested-by: Szymon Kłos 
Reviewed-on: https://gerrit.libreoffice.org/72280
Reviewed-by: Michael Stahl 
Tested-by: Jenkins
(cherry picked from commit 4bba6c122c3bb3468bccd69d53d70d00fd00bdcc)

Change-Id: Ie63c8d7e001c90f40cf7504fd8248a6742e9d244
Reviewed-on: https://gerrit.libreoffice.org/80553
Reviewed-by: Samuel Mehrbrodt 
Tested-by: Samuel Mehrbrodt 

diff --git a/sw/source/uibase/dbui/dbmgr.cxx b/sw/source/uibase/dbui/dbmgr.cxx
index de0a9ad8869d..a4c618462f5f 100644
--- a/sw/source/uibase/dbui/dbmgr.cxx
+++ b/sw/source/uibase/dbui/dbmgr.cxx
@@ -1319,453 +1319,464 @@ bool SwDBManager::MergeMailFiles(SwWrtShell* 
pSourceShell,
 vcl::Window *pSourceWindow = nullptr;
 std::shared_ptr xProgressDlg;
 
-if( !bIsMergeSilent )
+try
 {
-// construct the process dialog
-pSourceWindow = &pSourceShell->GetView().GetEditWin();
-if (!bMT_PRINTER)
-xProgressDlg.reset(new 
CreateMonitor(pSourceWindow->GetFrameWeld()));
-else
+if( !bIsMergeSilent )
 {
-xProgressDlg.reset(new 
PrintMonitor(pSourceWindow->GetFrameWeld()));
-static_cast(xProgressDlg.get())->set_title(
-pSourceDocSh->GetTitle(22));
-}
-weld::DialogController::runAsync(xProgressDlg, [this, 
&xProgressDlg](sal_Int32 nResult){
-if (nResult == RET_CANCEL)
-MergeCancel();
-xProgressDlg.reset();
-});
-
-Application::Reschedule( true );
-}
-
-if( bCreateSingleFile && !pTargetView )
-{
-// create a target docshell to put the merged document into
-xTargetDocShell = lcl_CreateWorkingDocument( WorkingDocType::TARGET,
-*pSourceShell, bMT_SHELL ? pSourceWindow : nullptr,
-nullptr, &pTargetView, &pTargetShell, &pTargetDoc );
+// construct the process dialog
+pSourceWindow = &pSourceShell->GetView().GetEditWin();
+if (!bMT_PRINTER)
+xProgressDlg.reset(new 
CreateMonitor(pSourceWindow->GetFrameWeld()));
+else
+{
+xProgressDlg.reset(new 
PrintMonitor(pSourceWindow->GetFrameWeld()));
+static_cast(xProgressDlg.get())->set_title(
+pSourceDocSh->GetTitle(22));
+}
+weld::DialogController::runAsync(xProgressDlg, [this, 
&xProgressDlg](sal_Int32 nResult){
+if (nResult == RET_CANCEL)
+MergeCancel();
+xProgressDlg.reset();
+});
 
-// import current print settings
-const SwPrintData &rPrintData = 
pSourceShell->getIDocumentDeviceAccess().getPrintData();
-pTargetDoc->getIDocumentDeviceAccess().setPrintData(rPrintData);
+Application::Reschedule( true );
+}
 
-if (nMaxDumpDocs)
-lcl_SaveDebugDoc( xTargetDocShell.get(), "MergeDoc" );
-}
-else if( pTargetView )
-{
-pTargetShell = pTargetView->GetWrtShellPtr();
-pTargetDoc = pTargetShell->GetDoc();
-xTargetDocShell = pTargetView->GetDocShell();
-}
+if( bCreateSingleFile && !pTargetView )
+{
+// create a target docshell to put the merged document into
+xTargetDocShell = lcl_CreateWorkingDocument( 
WorkingDocType::TARGET,
+*pSourceShell, bMT_SHELL ? pSourceWindow : nullptr,
+nullptr, &pTargetView, &pTargetShell, &pTargetDoc );
 
-if( bCreateSingleFile )
-{
-// determine the page style and number used at the start of the source 
document
-pSourceShell->SttEndDoc(true);
-nStartingPageNo = pSourceShell->GetVirtPageNum();
-}
+// import current print settings
+const SwPrintData &rPrintData = 
pSourceShell->getIDocumentDeviceAccess().getPrintData();
+pTargetDoc->getIDocumentDeviceAccess().setPrintData(rPrintData);
 
-// Progress, to prohibit KeyInputs
-SfxProgress aProgress(pSourceDocSh, ::aEmptyOUStr, 1);
+if (nMaxDumpDocs)
+lcl_SaveDebugDoc( xTargetDocShell.get(), "MergeDoc" );
+}
+else if( pTargetView )
+{
+pTargetShell = pTargetView->GetWrtShellPtr();
+pTargetDoc = pTargetShell->GetDoc();
+xTargetDocShell = pTargetView->GetDocShell();
+}
 
-// lock all dispatchers
-SfxViewFrame* pViewFrame = Sfx