[Libreoffice-commits] core.git: vcl/source

Caolán McNamara (via logerrit) logerrit at kemper.freedesktop.org
Thu Dec 24 11:53:54 UTC 2020


 vcl/source/filter/png/pngread.cxx |  117 ++++++++++++++++++++------------------
 1 file changed, 63 insertions(+), 54 deletions(-)

New commits:
commit 95407c39168d186ee44e67b1a6a4bcf592c58b84
Author:     Caolán McNamara <caolanm at redhat.com>
AuthorDate: Wed Dec 23 19:20:16 2020 +0000
Commit:     Caolán McNamara <caolanm at redhat.com>
CommitDate: Thu Dec 24 12:53:09 2020 +0100

    ofz#28902 uncaught exception
    
    Change-Id: I94dc0e2c8466546772ae7fdd1a0f3501a8f9bfaa
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/108245
    Tested-by: Jenkins
    Reviewed-by: Caolán McNamara <caolanm at redhat.com>

diff --git a/vcl/source/filter/png/pngread.cxx b/vcl/source/filter/png/pngread.cxx
index cda1c3e9e4b5..2155648d1273 100644
--- a/vcl/source/filter/png/pngread.cxx
+++ b/vcl/source/filter/png/pngread.cxx
@@ -256,68 +256,77 @@ PNGReaderImpl::~PNGReaderImpl()
 
 bool PNGReaderImpl::ReadNextChunk()
 {
-    if( maChunkIter == maChunkSeq.end() )
+    try
     {
-        // get the next chunk from the stream
-
-        // unless we are at the end of the PNG stream
-        if (!mrPNGStream.good() || mrPNGStream.remainingSize() < 8)
-            return false;
-        if( !maChunkSeq.empty() && (maChunkSeq.back().nType == PNGCHUNK_IEND) )
-            return false;
-
-        PNGReader::ChunkData aDummyChunk;
-        maChunkIter = maChunkSeq.insert( maChunkSeq.end(), aDummyChunk );
-        PNGReader::ChunkData& rChunkData = *maChunkIter;
-
-        // read the chunk header
-        mnChunkLen = 0;
-        mnChunkType = 0;
-        mrPNGStream.ReadInt32( mnChunkLen ).ReadUInt32( mnChunkType );
-        rChunkData.nType = mnChunkType;
-
-        // fdo#61847 truncate over-long, trailing chunks
-        const std::size_t nStreamPos = mrPNGStream.Tell();
-        if( mnChunkLen < 0 || nStreamPos + mnChunkLen >= mnStreamSize )
-            mnChunkLen = mnStreamSize - nStreamPos;
-
-        // calculate chunktype CRC (swap it back to original byte order)
-        sal_uInt32 nChunkType = mnChunkType;
-        #if defined(__LITTLEENDIAN) || defined(OSL_LITENDIAN)
-        nChunkType = OSL_SWAPDWORD( nChunkType );
-        #endif
-        sal_uInt32 nCRC32 = rtl_crc32( 0, &nChunkType, 4 );
-
-        // read the chunk data and check the CRC
-        if( mnChunkLen && !mrPNGStream.eof() )
+        if( maChunkIter == maChunkSeq.end() )
         {
-            rChunkData.aData.resize( mnChunkLen );
-
-            sal_Int32 nBytesRead = 0;
-            do
+            // get the next chunk from the stream
+
+            // unless we are at the end of the PNG stream
+            if (!mrPNGStream.good() || mrPNGStream.remainingSize() < 8)
+                return false;
+            if( !maChunkSeq.empty() && (maChunkSeq.back().nType == PNGCHUNK_IEND) )
+                return false;
+
+            PNGReader::ChunkData aDummyChunk;
+            maChunkIter = maChunkSeq.insert( maChunkSeq.end(), aDummyChunk );
+            PNGReader::ChunkData& rChunkData = *maChunkIter;
+
+            // read the chunk header
+            mnChunkLen = 0;
+            mnChunkType = 0;
+            mrPNGStream.ReadInt32( mnChunkLen ).ReadUInt32( mnChunkType );
+            rChunkData.nType = mnChunkType;
+
+            // fdo#61847 truncate over-long, trailing chunks
+            const std::size_t nStreamPos = mrPNGStream.Tell();
+            if( mnChunkLen < 0 || nStreamPos + mnChunkLen >= mnStreamSize )
+                mnChunkLen = mnStreamSize - nStreamPos;
+
+            // calculate chunktype CRC (swap it back to original byte order)
+            sal_uInt32 nChunkType = mnChunkType;
+            #if defined(__LITTLEENDIAN) || defined(OSL_LITENDIAN)
+            nChunkType = OSL_SWAPDWORD( nChunkType );
+            #endif
+            sal_uInt32 nCRC32 = rtl_crc32( 0, &nChunkType, 4 );
+
+            // read the chunk data and check the CRC
+            if( mnChunkLen && !mrPNGStream.eof() )
             {
-                sal_uInt8& rPtr = rChunkData.aData[nBytesRead];
-                nBytesRead += mrPNGStream.ReadBytes(&rPtr, mnChunkLen - nBytesRead);
-            } while (nBytesRead < mnChunkLen && mrPNGStream.good());
+                rChunkData.aData.resize( mnChunkLen );
+
+                sal_Int32 nBytesRead = 0;
+                do
+                {
+                    sal_uInt8& rPtr = rChunkData.aData[nBytesRead];
+                    nBytesRead += mrPNGStream.ReadBytes(&rPtr, mnChunkLen - nBytesRead);
+                } while (nBytesRead < mnChunkLen && mrPNGStream.good());
 
-            nCRC32 = rtl_crc32( nCRC32, rChunkData.aData.data(), mnChunkLen );
-            maDataIter = rChunkData.aData.begin();
+                nCRC32 = rtl_crc32( nCRC32, rChunkData.aData.data(), mnChunkLen );
+                maDataIter = rChunkData.aData.begin();
+            }
+            sal_uInt32 nCheck(0);
+            mrPNGStream.ReadUInt32( nCheck );
+            if (!mbIgnoreCRC && nCRC32 != nCheck)
+                return false;
         }
-        sal_uInt32 nCheck(0);
-        mrPNGStream.ReadUInt32( nCheck );
-        if (!mbIgnoreCRC && nCRC32 != nCheck)
-            return false;
+        else
+        {
+            // the next chunk was already read
+            mnChunkType = (*maChunkIter).nType;
+            mnChunkLen = (*maChunkIter).aData.size();
+            maDataIter = (*maChunkIter).aData.begin();
+        }
+
+        ++maChunkIter;
+        return mnChunkType != PNGCHUNK_IEND;
     }
-    else
+    catch (const SvStreamEOFException&)
     {
-        // the next chunk was already read
-        mnChunkType = (*maChunkIter).nType;
-        mnChunkLen = (*maChunkIter).aData.size();
-        maDataIter = (*maChunkIter).aData.begin();
+        mbStatus = false;
+        SAL_WARN("vcl", "EOF");
     }
-
-    ++maChunkIter;
-    return mnChunkType != PNGCHUNK_IEND;
+    return false;
 }
 
 const std::vector< vcl::PNGReader::ChunkData >& PNGReaderImpl::GetAllChunks()


More information about the Libreoffice-commits mailing list