include/rtl/string.hxx | 12 ++++++++++++ include/rtl/ustring.hxx | 12 ++++++++++++ oox/source/ppt/pptfilterhelpers.cxx | 2 ++ sd/source/filter/eppt/pptexanimations.cxx | 2 ++ 4 files changed, 28 insertions(+)
New commits: commit 59915ec9211b90e5b7be164d0bfa26d9d9be4f5a Author: Noel Grandin <noelgran...@gmail.com> AuthorDate: Mon Sep 23 09:17:58 2024 +0200 Commit: Noel Grandin <noel.gran...@collabora.co.uk> CommitDate: Tue Sep 24 12:09:41 2024 +0200 in OUString find functions, assert that fromIndex >= 0 otherwise, the pointer calculations mean that we will start searching inside data that does not belong to the character array. which flushes out a couple of problem cases Change-Id: Ide9edf23900289343077c406d95614057c1d1a6c Reviewed-on: https://gerrit.libreoffice.org/c/core/+/173807 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk> diff --git a/include/rtl/string.hxx b/include/rtl/string.hxx index b98e9e01f674..43a31e92303a 100644 --- a/include/rtl/string.hxx +++ b/include/rtl/string.hxx @@ -940,12 +940,14 @@ public: #if defined LIBO_INTERNAL_ONLY bool match( std::string_view str, sal_Int32 fromIndex = 0 ) const { + assert(fromIndex >= 0); return rtl_str_shortenedCompare_WithLength( pData->buffer+fromIndex, pData->length-fromIndex, str.data(), str.size(), str.size() ) == 0; } #else bool match( const OString & str, sal_Int32 fromIndex = 0 ) const { + assert(fromIndex >= 0); return rtl_str_shortenedCompare_WithLength( pData->buffer+fromIndex, pData->length-fromIndex, str.pData->buffer, str.pData->length, str.pData->length ) == 0; } @@ -962,6 +964,7 @@ public: RTL_STRING_CONST_FUNCTION assert( libreoffice_internal::ConstCharArrayDetector<T>::isValid(literal)); + assert(fromIndex >= 0); return rtl_str_shortenedCompare_WithLength( pData->buffer + fromIndex, pData->length - fromIndex, @@ -992,6 +995,7 @@ public: char const * str, sal_Int32 strLength, sal_Int32 fromIndex = 0) const { + assert(fromIndex >= 0); return rtl_str_shortenedCompare_WithLength( pData->buffer + fromIndex, pData->length - fromIndex, str, strLength, strLength) == 0; @@ -1026,6 +1030,7 @@ public: #if defined LIBO_INTERNAL_ONLY bool matchIgnoreAsciiCase( std::string_view str, sal_Int32 fromIndex = 0 ) const { + assert(fromIndex >= 0); return rtl_str_shortenedCompareIgnoreAsciiCase_WithLength( pData->buffer+fromIndex, pData->length-fromIndex, str.data(), str.size(), str.size() ) == 0; @@ -1033,6 +1038,7 @@ public: #else bool matchIgnoreAsciiCase( const OString & str, sal_Int32 fromIndex = 0 ) const { + assert(fromIndex >= 0); return rtl_str_shortenedCompareIgnoreAsciiCase_WithLength( pData->buffer+fromIndex, pData->length-fromIndex, str.pData->buffer, str.pData->length, str.pData->length ) == 0; @@ -1049,6 +1055,7 @@ public: RTL_STRING_CONST_FUNCTION assert( libreoffice_internal::ConstCharArrayDetector<T>::isValid(literal)); + assert(fromIndex >= 0); return rtl_str_shortenedCompareIgnoreAsciiCase_WithLength( pData->buffer+fromIndex, pData->length-fromIndex, @@ -1747,6 +1754,7 @@ public: */ sal_Int32 indexOf( char ch, sal_Int32 fromIndex = 0 ) const { + assert(fromIndex >= 0); sal_Int32 ret = rtl_str_indexOfChar_WithLength( pData->buffer+fromIndex, pData->length-fromIndex, ch ); return (ret < 0 ? ret : ret+fromIndex); } @@ -1800,6 +1808,7 @@ public: #if defined LIBO_INTERNAL_ONLY sal_Int32 indexOf( std::string_view str, sal_Int32 fromIndex = 0 ) const { + assert(fromIndex >= 0); sal_Int32 ret = rtl_str_indexOfStr_WithLength( pData->buffer+fromIndex, pData->length-fromIndex, str.data(), str.size() ); return (ret < 0 ? ret : ret+fromIndex); @@ -1807,6 +1816,7 @@ public: #else sal_Int32 indexOf( const OString & str, sal_Int32 fromIndex = 0 ) const { + assert(fromIndex >= 0); sal_Int32 ret = rtl_str_indexOfStr_WithLength( pData->buffer+fromIndex, pData->length-fromIndex, str.pData->buffer, str.pData->length ); return (ret < 0 ? ret : ret+fromIndex); @@ -1823,6 +1833,7 @@ public: RTL_STRING_CONST_FUNCTION assert( libreoffice_internal::ConstCharArrayDetector<T>::isValid(literal)); + assert(fromIndex >= 0); sal_Int32 n = rtl_str_indexOfStr_WithLength( pData->buffer + fromIndex, pData->length - fromIndex, libreoffice_internal::ConstCharArrayDetector<T>::toPointer(literal), @@ -1851,6 +1862,7 @@ public: sal_Int32 indexOfL(char const * str, sal_Int32 len, sal_Int32 fromIndex = 0) const { + assert(fromIndex >= 0); sal_Int32 n = rtl_str_indexOfStr_WithLength( pData->buffer + fromIndex, pData->length - fromIndex, str, len); return n < 0 ? n : n + fromIndex; diff --git a/include/rtl/ustring.hxx b/include/rtl/ustring.hxx index b73d0f75a68c..8272cdb22c55 100644 --- a/include/rtl/ustring.hxx +++ b/include/rtl/ustring.hxx @@ -1076,6 +1076,7 @@ public: */ #if defined LIBO_INTERNAL_ONLY bool match(std::u16string_view sv, sal_Int32 fromIndex = 0) const { + assert(fromIndex >= 0); return rtl_ustr_shortenedCompare_WithLength( pData->buffer + fromIndex, pData->length - fromIndex, sv.data(), sv.size(), @@ -1085,6 +1086,7 @@ public: #else bool match( const OUString & str, sal_Int32 fromIndex = 0 ) const { + assert(fromIndex >= 0); return rtl_ustr_shortenedCompare_WithLength( pData->buffer+fromIndex, pData->length-fromIndex, str.pData->buffer, str.pData->length, str.pData->length ) == 0; } @@ -1100,6 +1102,7 @@ public: { assert( libreoffice_internal::ConstCharArrayDetector<T>::isValid(literal)); + assert(fromIndex >= 0); return rtl_ustr_ascii_shortenedCompare_WithLength( pData->buffer+fromIndex, pData->length-fromIndex, @@ -1129,6 +1132,7 @@ public: */ #if defined LIBO_INTERNAL_ONLY bool matchIgnoreAsciiCase(std::u16string_view sv, sal_Int32 fromIndex = 0) const { + assert(fromIndex >= 0); return rtl_ustr_shortenedCompareIgnoreAsciiCase_WithLength( pData->buffer + fromIndex, pData->length - fromIndex, sv.data(), sv.size(), @@ -1138,6 +1142,7 @@ public: #else bool matchIgnoreAsciiCase( const OUString & str, sal_Int32 fromIndex = 0 ) const { + assert(fromIndex >= 0); return rtl_ustr_shortenedCompareIgnoreAsciiCase_WithLength( pData->buffer+fromIndex, pData->length-fromIndex, str.pData->buffer, str.pData->length, str.pData->length ) == 0; @@ -1396,6 +1401,7 @@ public: */ bool matchAsciiL( const char* asciiStr, sal_Int32 asciiStrLength, sal_Int32 fromIndex = 0 ) const { + assert(fromIndex >= 0); return rtl_ustr_ascii_shortenedCompare_WithLength( pData->buffer+fromIndex, pData->length-fromIndex, asciiStr, asciiStrLength ) == 0; } @@ -1433,6 +1439,7 @@ public: */ bool matchIgnoreAsciiCaseAsciiL( const char* asciiStr, sal_Int32 asciiStrLength, sal_Int32 fromIndex = 0 ) const { + assert(fromIndex >= 0); return rtl_ustr_ascii_shortenedCompareIgnoreAsciiCase_WithLength( pData->buffer+fromIndex, pData->length-fromIndex, asciiStr, asciiStrLength ) == 0; } @@ -2314,6 +2321,7 @@ public: */ sal_Int32 indexOf( sal_Unicode ch, sal_Int32 fromIndex = 0 ) const { + assert(fromIndex >= 0); sal_Int32 ret = rtl_ustr_indexOfChar_WithLength( pData->buffer+fromIndex, pData->length-fromIndex, ch ); return (ret < 0 ? ret : ret+fromIndex); } @@ -2366,6 +2374,7 @@ public: */ #if defined LIBO_INTERNAL_ONLY sal_Int32 indexOf(std::u16string_view sv, sal_Int32 fromIndex = 0) const { + assert(fromIndex >= 0); auto const n = rtl_ustr_indexOfStr_WithLength( pData->buffer + fromIndex, pData->length - fromIndex, sv.data(), sv.size()); return n < 0 ? n : n + fromIndex; @@ -2373,6 +2382,7 @@ public: #else sal_Int32 indexOf( const OUString & str, sal_Int32 fromIndex = 0 ) const { + assert(fromIndex >= 0); sal_Int32 ret = rtl_ustr_indexOfStr_WithLength( pData->buffer+fromIndex, pData->length-fromIndex, str.pData->buffer, str.pData->length ); return (ret < 0 ? ret : ret+fromIndex); @@ -2389,6 +2399,7 @@ public: { assert( libreoffice_internal::ConstCharArrayDetector<T>::isValid(literal)); + assert(fromIndex >= 0); sal_Int32 n = rtl_ustr_indexOfAscii_WithLength( pData->buffer + fromIndex, pData->length - fromIndex, libreoffice_internal::ConstCharArrayDetector<T>::toPointer(literal), @@ -2422,6 +2433,7 @@ public: sal_Int32 indexOfAsciiL( char const * str, sal_Int32 len, sal_Int32 fromIndex = 0) const { + assert(fromIndex >= 0); sal_Int32 ret = rtl_ustr_indexOfAscii_WithLength( pData->buffer + fromIndex, pData->length - fromIndex, str, len); return ret < 0 ? ret : ret + fromIndex; diff --git a/oox/source/ppt/pptfilterhelpers.cxx b/oox/source/ppt/pptfilterhelpers.cxx index 054bf6260c07..74de14c01c6d 100644 --- a/oox/source/ppt/pptfilterhelpers.cxx +++ b/oox/source/ppt/pptfilterhelpers.cxx @@ -160,6 +160,8 @@ namespace oox::ppt { while (*ps) { + if (nIndex == -1) + nIndex = 0; const OUString aSearch(OUString::createFromAscii(*ps)); while ((nIndex = rString.indexOf(aSearch, nIndex)) != -1) { diff --git a/sd/source/filter/eppt/pptexanimations.cxx b/sd/source/filter/eppt/pptexanimations.cxx index 353a20b9c520..b40137bb9cdc 100644 --- a/sd/source/filter/eppt/pptexanimations.cxx +++ b/sd/source/filter/eppt/pptexanimations.cxx @@ -118,6 +118,8 @@ static void ImplTranslateAttribute( OUString& rString, const TranslateMode eTran while( *ps ) { + if (nIndex == -1) + nIndex = 0; const OUString aSearch( OUString::createFromAscii( *ps ) ); while( (nIndex = rString.indexOf( aSearch, nIndex )) != -1 ) {