diff options
author | Caolán McNamara <caolanm@redhat.com> | 2015-01-20 13:21:36 +0000 |
---|---|---|
committer | Michael Stahl <mstahl@redhat.com> | 2015-01-20 16:04:00 +0000 |
commit | 872dca364233067379056ba26e0729679b789b37 (patch) | |
tree | 4b38de6e4cd2ff111ed764ce3deeb6cba39f01cc | |
parent | 7c9f9dc770aa98c936b31867764db61d7d97cdeb (diff) |
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@redhat.com>
Reviewed-by: Michael Stahl <mstahl@redhat.com>
-rw-r--r-- | vcl/source/filter/graphicfilter.cxx | 28 |
1 files changed, 16 insertions, 12 deletions
diff --git a/vcl/source/filter/graphicfilter.cxx b/vcl/source/filter/graphicfilter.cxx index b47e6745c44d..c04f4c326720 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; |