Kaydet (Commit) c00601da authored tarafından Eike Rathke's avatar Eike Rathke

fdo#60259 prevent crash when searching backward for $ anchor regex

Old code wasn't prepared that searching for $ may actually return a
result set pointing behind the search string which it does with the ICU
regex engine.

Change-Id: I95612f676008cf6758a5ade3d674f38168944a4d
üst f1ec7dc6
...@@ -208,16 +208,26 @@ SearchResult TextSearch::searchForward( const OUString& searchStr, sal_Int32 sta ...@@ -208,16 +208,26 @@ SearchResult TextSearch::searchForward( const OUString& searchStr, sal_Int32 sta
sres = (this->*fnForward)( in_str, newStartPos, newEndPos ); sres = (this->*fnForward)( in_str, newStartPos, newEndPos );
for ( int k = 0; k < sres.startOffset.getLength(); k++ ) // Map offsets back to untransliterated string.
const sal_Int32 nOffsets = offset.getLength();
if (nOffsets)
{ {
if (sres.startOffset[k]) // For regex nGroups is the number of groups+1 with group 0 being
sres.startOffset[k] = offset[sres.startOffset[k]]; // the entire match.
// JP 20.6.2001: end is ever exclusive and then don't return const sal_Int32 nGroups = sres.startOffset.getLength();
// the position of the next character - return the for ( sal_Int32 k = 0; k < nGroups; k++ )
// next position behind the last found character! {
// "a b c" find "b" must return 2,3 and not 2,4!!! const sal_Int32 nStart = sres.startOffset[k];
if (sres.endOffset[k]) if (nStart > 0)
sres.endOffset[k] = offset[sres.endOffset[k]-1] + 1; sres.startOffset[k] = (nStart < nOffsets ? offset[nStart] : (offset[nOffsets - 1] + 1));
// JP 20.6.2001: end is ever exclusive and then don't return
// the position of the next character - return the
// next position behind the last found character!
// "a b c" find "b" must return 2,3 and not 2,4!!!
const sal_Int32 nStop = sres.endOffset[k];
if (nStop > 0)
sres.endOffset[k] = offset[(nStop <= nOffsets ? nStop : nOffsets) - 1] + 1;
}
} }
} }
else else
...@@ -297,16 +307,26 @@ SearchResult TextSearch::searchBackward( const OUString& searchStr, sal_Int32 st ...@@ -297,16 +307,26 @@ SearchResult TextSearch::searchBackward( const OUString& searchStr, sal_Int32 st
sres = (this->*fnBackward)( in_str, newStartPos, newEndPos ); sres = (this->*fnBackward)( in_str, newStartPos, newEndPos );
for ( int k = 0; k < sres.startOffset.getLength(); k++ ) // Map offsets back to untransliterated string.
const sal_Int32 nOffsets = offset.getLength();
if (nOffsets)
{ {
if (sres.startOffset[k]) // For regex nGroups is the number of groups+1 with group 0 being
sres.startOffset[k] = offset[sres.startOffset[k] - 1] + 1; // the entire match.
// JP 20.6.2001: end is ever exclusive and then don't return const sal_Int32 nGroups = sres.startOffset.getLength();
// the position of the next character - return the for ( sal_Int32 k = 0; k < nGroups; k++ )
// next position behind the last found character! {
// "a b c" find "b" must return 2,3 and not 2,4!!! const sal_Int32 nStart = sres.startOffset[k];
if (sres.endOffset[k]) if (nStart > 0)
sres.endOffset[k] = offset[sres.endOffset[k]]; sres.startOffset[k] = offset[(nStart <= nOffsets ? nStart : nOffsets) - 1] + 1;
// JP 20.6.2001: end is ever exclusive and then don't return
// the position of the next character - return the
// next position behind the last found character!
// "a b c" find "b" must return 2,3 and not 2,4!!!
const sal_Int32 nStop = sres.endOffset[k];
if (nStop > 0)
sres.endOffset[k] = (nStop < nOffsets ? offset[nStop] : (offset[nOffsets - 1] + 1));
}
} }
} }
else else
......
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