[Libreoffice-commits] core.git: Branch 'libreoffice-4-4' - vcl/source

Caolán McNamara caolanm at redhat.com
Tue Jan 20 08:04:38 PST 2015


 vcl/source/filter/graphicfilter.cxx |   28 ++++++++++++++++------------
 1 file changed, 16 insertions(+), 12 deletions(-)

New commits:
commit 872dca364233067379056ba26e0729679b789b37
Author: Caolán McNamara <caolanm at redhat.com>
Date:   Tue Jan 20 13:21:36 2015 +0000

    accidentally ran make with VALGRIND set and walked away...
    
    and found this bug triggered by CppunitTest_filter_eps_test when
    I got back
    
    Change-Id: I20943e5bd0fbf8aed923699dd5f1e88fada43e81
    (cherry picked from commit 6cf58a33676cebc9f2c1d26163793ba7dce46262)
    Reviewed-on: https://gerrit.libreoffice.org/14044
    Tested-by: Michael Stahl <mstahl at redhat.com>
    Reviewed-by: Michael Stahl <mstahl at redhat.com>

diff --git a/vcl/source/filter/graphicfilter.cxx b/vcl/source/filter/graphicfilter.cxx
index b47e674..c04f4c3 100644
--- a/vcl/source/filter/graphicfilter.cxx
+++ b/vcl/source/filter/graphicfilter.cxx
@@ -256,9 +256,8 @@ bool isPCT(SvStream& rStream, sal_uLong nStreamPos, sal_uLong nStreamLen)
 
 static bool ImpPeekGraphicFormat( SvStream& rStream, OUString& rFormatExtension, bool bTest )
 {
-    sal_uInt16  i;
     sal_uInt8   sFirstBytes[ 256 ];
-    sal_uLong   nFirstLong,nSecondLong;
+    sal_uLong   nFirstLong(0), nSecondLong(0);
     sal_uLong   nStreamPos = rStream.Tell();
 
     rStream.Seek( STREAM_SEEK_TO_END );
@@ -275,28 +274,33 @@ static bool ImpPeekGraphicFormat( SvStream& rStream, OUString& rFormatExtension,
         nStreamLen = rStream.Tell() - nStreamPos;
         rStream.Seek( nStreamPos );
     }
+
     if (!nStreamLen)
     {
         return false; // this prevents at least a STL assertion
     }
     else if (nStreamLen >= 256)
-    {   // load first 256 bytes into a buffer
-        rStream.Read( sFirstBytes, 256 );
+    {
+        // load first 256 bytes into a buffer
+        sal_uLong nRead = rStream.Read(sFirstBytes, 256);
+        if (nRead < 256)
+            nStreamLen = nRead;
     }
     else
     {
-        rStream.Read( sFirstBytes, nStreamLen );
-
-        for( i = (sal_uInt16) nStreamLen; i < 256; i++ )
-            sFirstBytes[ i ]=0;
+        nStreamLen = rStream.Read(sFirstBytes, nStreamLen);
     }
 
-    if( rStream.GetError() )
+
+    if (rStream.GetError())
         return false;
 
+    for (sal_uLong i = nStreamLen; i < 256; ++i)
+        sFirstBytes[i] = 0;
+
     // Accommodate the first 8 bytes in nFirstLong, nSecondLong
     // Big-Endian:
-    for( i = 0, nFirstLong = 0L, nSecondLong = 0L; i < 4; i++ )
+    for (int i = 0; i < 4; ++i)
     {
         nFirstLong=(nFirstLong<<8)|(sal_uLong)sFirstBytes[i];
         nSecondLong=(nSecondLong<<8)|(sal_uLong)sFirstBytes[i+4];
@@ -325,7 +329,7 @@ static bool ImpPeekGraphicFormat( SvStream& rStream, OUString& rFormatExtension,
             sal_uInt8 nMagic;
             bool bOK=true;
             rStream.ReadUInt16( nFieldSize ).ReadUChar( nMagic );
-            for (i=0; i<3; i++) {
+            for (int i=0; i<3; i++) {
                 if (nFieldSize<6) { bOK=false; break; }
                 if (nStreamLen < rStream.Tell() + nFieldSize ) { bOK=false; break; }
                 rStream.SeekRel(nFieldSize-3);
@@ -526,7 +530,7 @@ static bool ImpPeekGraphicFormat( SvStream& rStream, OUString& rFormatExtension,
         }
 
         // ASCII DXF File Format
-        i=0;
+        int i=0;
         while (i<256 && sFirstBytes[i]<=32)
             ++i;
 


More information about the Libreoffice-commits mailing list