sc/source/filter/excel/xistream.cxx |   14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

New commits:
commit 4c902618fbcae1ce0645dcbfcf74d703ffaf4c1d
Author:     Noel Grandin <[email protected]>
AuthorDate: Mon Nov 10 12:18:38 2025 +0200
Commit:     Noel Grandin <[email protected]>
CommitDate: Mon Nov 10 14:21:30 2025 +0100

    fix read loop in XclImpStream::CopyToStream
    
    we want to write the number of bytes we read in
    the current iteration of the loop, not the total
    number of bytes read up till now.
    
    this bug dates back to
        commit ead57c596df688a4e51f4abcb0014647e0c2e2af
        Author: Oliver Bolte <[email protected]>
        Date:   Wed Aug 11 08:53:27 2004 +0000
        INTEGRATION: CWS encryption (1.5.6); FILE MERGED
    
    Change-Id: I1dd55188ec0a23ed1595e57b2bf6caa202c0e7ae
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/193732
    Reviewed-by: Noel Grandin <[email protected]>
    Tested-by: Jenkins

diff --git a/sc/source/filter/excel/xistream.cxx 
b/sc/source/filter/excel/xistream.cxx
index ebb927ae8137..b691ff7a0e94 100644
--- a/sc/source/filter/excel/xistream.cxx
+++ b/sc/source/filter/excel/xistream.cxx
@@ -745,7 +745,7 @@ std::size_t XclImpStream::Read( void* pData, std::size_t 
nBytes )
 
 std::size_t XclImpStream::CopyToStream( SvStream& rOutStrm, std::size_t nBytes 
)
 {
-    std::size_t nRet = 0;
+    std::size_t nBytesCopied = 0;
     if (mbValid && nBytes)
     {
         const std::size_t nMaxBuffer = 4096;
@@ -757,14 +757,14 @@ std::size_t XclImpStream::CopyToStream( SvStream& 
rOutStrm, std::size_t nBytes )
             if (!nBytesLeft)
                 break;
             std::size_t nReadSize = o3tl::sanitizing_min(nBytesLeft, 
nMaxBuffer);
-            nRet += Read(aBuffer.data(), nReadSize);
-            // writing more bytes than read results in invalid memory access
-            SAL_WARN_IF(nRet != nReadSize, "sc", "read less bytes than 
requested");
-            rOutStrm.WriteBytes(aBuffer.data(), nReadSize);
-            nBytesLeft -= nReadSize;
+            auto nBytesRead = Read(aBuffer.data(), nReadSize);
+            assert(nBytesRead <= nReadSize);
+            nBytesCopied += nBytesRead;
+            rOutStrm.WriteBytes(aBuffer.data(), nBytesRead);
+            nBytesLeft -= nBytesRead;
         }
     }
-    return nRet;
+    return nBytesCopied;
 }
 
 void XclImpStream::CopyRecordToStream( SvStream& rOutStrm )

Reply via email to