Kaydet (Commit) b6d45f26 authored tarafından Michael Stahl's avatar Michael Stahl

fdo#60732: check max size in SwTxtNode::ReplaceText

Also adjust SwUndoReplace to not assume that everything was inserted and
use the stored indexes instead in Undo.

Change-Id: I52f3aaf063c2b1bd52381bdc19e29a41a12c3847
üst d47218d7
...@@ -333,6 +333,8 @@ public: ...@@ -333,6 +333,8 @@ public:
const SwIndex & rStart, const xub_StrLen nLen); const SwIndex & rStart, const xub_StrLen nLen);
/// replace nDelLen characters at rStart with rText /// replace nDelLen characters at rStart with rText
/// in case the replacement does not fit, it is partially inserted up to
/// TXTNODE_MAX
void ReplaceText( const SwIndex& rStart, const xub_StrLen nDelLen, void ReplaceText( const SwIndex& rStart, const xub_StrLen nDelLen,
const XubString& rText ); const XubString& rText );
void ReplaceTextOnly( xub_StrLen nPos, xub_StrLen nLen, const XubString& rText, void ReplaceTextOnly( xub_StrLen nPos, xub_StrLen nLen, const XubString& rText,
......
...@@ -3322,11 +3322,23 @@ XubString SwTxtNode::GetRedlineTxt( xub_StrLen nIdx, xub_StrLen nLen, ...@@ -3322,11 +3322,23 @@ XubString SwTxtNode::GetRedlineTxt( xub_StrLen nIdx, xub_StrLen nLen,
*************************************************************************/ *************************************************************************/
void SwTxtNode::ReplaceText( const SwIndex& rStart, const xub_StrLen nDelLen, void SwTxtNode::ReplaceText( const SwIndex& rStart, const xub_StrLen nDelLen,
const XubString& rText ) const XubString& rStr)
{ {
OSL_ENSURE( rStart.GetIndex() < m_Text.Len() && OSL_ENSURE( rStart.GetIndex() < m_Text.Len() &&
rStart.GetIndex() + nDelLen <= m_Text.Len(), rStart.GetIndex() + nDelLen <= m_Text.Len(),
"SwTxtNode::ReplaceText: index out of bounds" ); "SwTxtNode::ReplaceText: index out of bounds" );
ssize_t const nOverflow(static_cast<ssize_t>(m_Text.Len())
+ static_cast<ssize_t>(rStr.Len()) - nDelLen - TXTNODE_MAX);
SAL_WARN_IF(nOverflow > 0, "sw.core",
"SwTxtNode::ReplaceText: node text with insertion > TXTNODE_MAX.");
OUString const sInserted(
(nOverflow > 0) ? rStr.Copy(0, rStr.Len() - nOverflow) : rStr);
if (sInserted.isEmpty())
{
return;
}
const xub_StrLen nStartPos = rStart.GetIndex(); const xub_StrLen nStartPos = rStart.GetIndex();
xub_StrLen nEndPos = nStartPos + nDelLen; xub_StrLen nEndPos = nStartPos + nDelLen;
xub_StrLen nLen = nDelLen; xub_StrLen nLen = nDelLen;
...@@ -3353,17 +3365,17 @@ void SwTxtNode::ReplaceText( const SwIndex& rStart, const xub_StrLen nDelLen, ...@@ -3353,17 +3365,17 @@ void SwTxtNode::ReplaceText( const SwIndex& rStart, const xub_StrLen nDelLen,
bool bOldExpFlg = IsIgnoreDontExpand(); bool bOldExpFlg = IsIgnoreDontExpand();
SetIgnoreDontExpand( true ); SetIgnoreDontExpand( true );
if( nLen && rText.Len() ) if (nLen && sInserted.getLength())
{ {
// dann das 1. Zeichen ersetzen den Rest loschen und einfuegen // dann das 1. Zeichen ersetzen den Rest loschen und einfuegen
// Dadurch wird die Attributierung des 1. Zeichen expandiert! // Dadurch wird die Attributierung des 1. Zeichen expandiert!
m_Text.SetChar( nStartPos, rText.GetChar( 0 ) ); m_Text.SetChar( nStartPos, sInserted[0] );
++((SwIndex&)rStart); ++((SwIndex&)rStart);
m_Text.Erase( rStart.GetIndex(), nLen - 1 ); m_Text.Erase( rStart.GetIndex(), nLen - 1 );
Update( rStart, nLen - 1, true ); Update( rStart, nLen - 1, true );
XubString aTmpTxt( rText ); aTmpTxt.Erase( 0, 1 ); XubString aTmpTxt(sInserted); aTmpTxt.Erase( 0, 1 );
m_Text.Insert( aTmpTxt, rStart.GetIndex() ); m_Text.Insert( aTmpTxt, rStart.GetIndex() );
Update( rStart, aTmpTxt.Len(), false ); Update( rStart, aTmpTxt.Len(), false );
} }
...@@ -3372,15 +3384,15 @@ void SwTxtNode::ReplaceText( const SwIndex& rStart, const xub_StrLen nDelLen, ...@@ -3372,15 +3384,15 @@ void SwTxtNode::ReplaceText( const SwIndex& rStart, const xub_StrLen nDelLen,
m_Text.Erase( nStartPos, nLen ); m_Text.Erase( nStartPos, nLen );
Update( rStart, nLen, true ); Update( rStart, nLen, true );
m_Text.Insert( rText, nStartPos ); m_Text.Insert( sInserted, nStartPos );
Update( rStart, rText.Len(), false ); Update( rStart, sInserted.getLength(), false );
} }
SetIgnoreDontExpand( bOldExpFlg ); SetIgnoreDontExpand( bOldExpFlg );
SwDelTxt aDelHint( nStartPos, nDelLen ); SwDelTxt aDelHint( nStartPos, nDelLen );
NotifyClients( 0, &aDelHint ); NotifyClients( 0, &aDelHint );
SwInsTxt aHint( nStartPos, rText.Len() ); SwInsTxt aHint( nStartPos, sInserted.getLength() );
NotifyClients( 0, &aHint ); NotifyClients( 0, &aHint );
} }
......
...@@ -672,11 +672,7 @@ void SwUndoReplace::Impl::UndoImpl(::sw::UndoRedoContext & rContext) ...@@ -672,11 +672,7 @@ void SwUndoReplace::Impl::UndoImpl(::sw::UndoRedoContext & rContext)
} }
SwIndex aIdx( pNd, m_nSttCnt ); SwIndex aIdx( pNd, m_nSttCnt );
if( m_nSttNd == m_nEndNd ) // don't look at m_sIns for deletion, maybe it was not completely inserted
{
pNd->EraseText( aIdx, sal_uInt16( m_sIns.getLength() ) );
}
else
{ {
rPam.GetPoint()->nNode = *pNd; rPam.GetPoint()->nNode = *pNd;
rPam.GetPoint()->nContent.Assign( pNd, m_nSttCnt ); rPam.GetPoint()->nContent.Assign( pNd, m_nSttCnt );
...@@ -783,13 +779,9 @@ void SwUndoReplace::Impl::RedoImpl(::sw::UndoRedoContext & rContext) ...@@ -783,13 +779,9 @@ void SwUndoReplace::Impl::RedoImpl(::sw::UndoRedoContext & rContext)
void SwUndoReplace::Impl::SetEnd(SwPaM const& rPam) void SwUndoReplace::Impl::SetEnd(SwPaM const& rPam)
{ {
if( rPam.GetPoint()->nNode != rPam.GetMark()->nNode ) const SwPosition* pEnd = rPam.End();
{ m_nEndNd = m_nOffset + pEnd->nNode.GetIndex();
// multiple paragraphs were inserted m_nEndCnt = pEnd->nContent.GetIndex();
const SwPosition* pEnd = rPam.End();
m_nEndNd = m_nOffset + pEnd->nNode.GetIndex();
m_nEndCnt = pEnd->nContent.GetIndex();
}
} }
......
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