diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2022-01-17 12:53:44 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2022-01-17 13:27:25 +0100 |
commit | 0e4bcbb67dda204ba78f99df68a63458c29e7470 (patch) | |
tree | a010f6dbb4e9c5062142488c62f4c151b0e83690 /sw/source/core/text | |
parent | bbc4360b5beb012adf1e2652328d3e18d66224aa (diff) |
tdf#145321 Crash scrolling DOCX to bottom
this is a consequence of
commit d4dc6b5cfdb02ad00a06ad32650948648abe010d
use std::vector for fetching DX array data
which made pre-existing bugs easier to see.
This crash made apparent that we have bad data ending up in
SwDrawTextInfo. So I added some asserts there to catch that.
However, that simply made apparent that there are bug(s) at
a higher level that I have no idea how to to fix.
So at the primary problem site in
SwTextCursor::GetModelPositionForViewPoint I clamp
the values to sane ones.
Change-Id: Ic74f6944932bbfc22e8cf9addf9e7511755b18be
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/128497
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'sw/source/core/text')
-rw-r--r-- | sw/source/core/text/inftxt.cxx | 4 | ||||
-rw-r--r-- | sw/source/core/text/itrcrsr.cxx | 6 |
2 files changed, 8 insertions, 2 deletions
diff --git a/sw/source/core/text/inftxt.cxx b/sw/source/core/text/inftxt.cxx index a5e588ebad0b..16af09c8ccbf 100644 --- a/sw/source/core/text/inftxt.cxx +++ b/sw/source/core/text/inftxt.cxx @@ -1230,7 +1230,9 @@ void SwTextPaintInfo::DrawBackBrush( const SwLinePortion &rPor ) const { continue; } - if (i >= TextFrameIndex(GetText().getLength()) + if ((i + TextFrameIndex(1) ).get() > GetText().getLength()) + ; // prevent crash by not passing bad data down to GetTextSize->SwDrawTextInfo + else if (i >= TextFrameIndex(GetText().getLength()) || GetText()[sal_Int32(i)] != CH_BLANK) { sal_uInt16 nOldWidth = rPor.Width(); diff --git a/sw/source/core/text/itrcrsr.cxx b/sw/source/core/text/itrcrsr.cxx index 841aff1f395a..1db90d64b4b4 100644 --- a/sw/source/core/text/itrcrsr.cxx +++ b/sw/source/core/text/itrcrsr.cxx @@ -1667,12 +1667,16 @@ TextFrameIndex SwTextCursor::GetModelPositionForViewPoint( SwPosition *pPos, con SwParaPortion* pPara = const_cast<SwParaPortion*>(GetInfo().GetParaPortion()); OSL_ENSURE( pPara, "No paragraph!" ); + // protect against bugs elsewhere + SAL_WARN_IF( aSizeInf.GetIdx().get() + pPor->GetLen().get() > aSizeInf.GetText().getLength(), "sw", "portion and text are out of sync" ); + TextFrameIndex nSafeLen( std::min(pPor->GetLen().get(), aSizeInf.GetText().getLength() - aSizeInf.GetIdx().get()) ); + SwDrawTextInfo aDrawInf( aSizeInf.GetVsh(), *aSizeInf.GetOut(), &pPara->GetScriptInfo(), aSizeInf.GetText(), aSizeInf.GetIdx(), - pPor->GetLen() ); + nSafeLen ); // Drop portion works like a multi portion, just its parts are not portions if( pPor->IsDropPortion() && static_cast<SwDropPortion*>(pPor)->GetLines() > 1 ) |