tools/source/stream/stream.cxx | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
New commits: commit af82f165caa17c6c4678705aa4084647a6825c2d Author: Stephan Bergmann <[email protected]> AuthorDate: Thu Feb 26 16:36:02 2026 +0100 Commit: Stephan Bergmann <[email protected]> CommitDate: Thu Feb 26 19:44:18 2026 +0100 Avoid unspecified behavior when checking for "pointer in range" ...which can easily cause wrong behavior. (Maybe we can eventually replace the use of Boost here with Standard C++, if something like <https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2024/p3234r1.html> "Utility to check if a pointer is in a given range" ever gets in.) Change-Id: I9122efdd3272613b27c33a0d7dbc04ad2d6e39e4 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/200454 Reviewed-by: Stephan Bergmann <[email protected]> Tested-by: Jenkins diff --git a/tools/source/stream/stream.cxx b/tools/source/stream/stream.cxx index 96f84c36517b..15baf7bfdbd6 100644 --- a/tools/source/stream/stream.cxx +++ b/tools/source/stream/stream.cxx @@ -41,6 +41,8 @@ #include <comphelper/fileurl.hxx> #include <comphelper/scopeguard.hxx> +#include <boost/core/pointer_in_range.hpp> + #include <unicode/ucsdet.h> #include <frozen/bits/elsa_std.h> @@ -1646,7 +1648,8 @@ std::size_t SvMemoryStream::PutData( const void* pData, std::size_t nCount ) } else { - const bool bSourceDataIsInsideBuffer = pData >= pBuf && pData < (pBuf + nSize); + const bool bSourceDataIsInsideBuffer = boost::pointer_in_range( + static_cast<sal_uInt8 const *>(pData), pBuf, pBuf + nSize); std::ptrdiff_t const offset = bSourceDataIsInsideBuffer ? static_cast<const char*>(pData) - reinterpret_cast<const char*>(pBuf) : 0; tools::Long nNewResize; if( nSize && nSize > nResize )
