diff options
author | Caolán McNamara <caolanm@redhat.com> | 2010-11-25 16:46:43 +0000 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2010-11-25 16:46:43 +0000 |
commit | f2f6bf1cbd97fdeac9433b9c79401137f3fc4f28 (patch) | |
tree | 2dc949fed9170a10a3947489f78a70aa0f76e21a /package | |
parent | 41a0d24763953c06d4859cac2109bc4dee77e55e (diff) |
Resolves: rhbz#656191 Catch bad alloc and convert to ZipIOException
Diffstat (limited to 'package')
-rw-r--r-- | package/source/zipapi/ZipFile.cxx | 45 |
1 files changed, 27 insertions, 18 deletions
diff --git a/package/source/zipapi/ZipFile.cxx b/package/source/zipapi/ZipFile.cxx index 475bcea9af7c..68ce5603ec50 100644 --- a/package/source/zipapi/ZipFile.cxx +++ b/package/source/zipapi/ZipFile.cxx @@ -638,29 +638,38 @@ sal_Bool ZipFile::readLOC( ZipEntry &rEntry ) aGrabber >> nExtraLen; rEntry.nOffset = static_cast < sal_Int32 > (aGrabber.getPosition()) + nPathLen + nExtraLen; - // read always in UTF8, some tools seem not to set UTF8 bit - uno::Sequence < sal_Int8 > aNameBuffer( nPathLen ); - sal_Int32 nRead = aGrabber.readBytes( aNameBuffer, nPathLen ); - if ( nRead < aNameBuffer.getLength() ) - aNameBuffer.realloc( nRead ); + sal_Bool bBroken = sal_False; - ::rtl::OUString sLOCPath = rtl::OUString::intern( (sal_Char *) aNameBuffer.getArray(), - aNameBuffer.getLength(), - RTL_TEXTENCODING_UTF8 ); + try + { + // read always in UTF8, some tools seem not to set UTF8 bit + uno::Sequence < sal_Int8 > aNameBuffer( nPathLen ); + sal_Int32 nRead = aGrabber.readBytes( aNameBuffer, nPathLen ); + if ( nRead < aNameBuffer.getLength() ) + aNameBuffer.realloc( nRead ); + + ::rtl::OUString sLOCPath = rtl::OUString::intern( (sal_Char *) aNameBuffer.getArray(), + aNameBuffer.getLength(), + RTL_TEXTENCODING_UTF8 ); + + if ( rEntry.nPathLen == -1 ) // the file was created + { + rEntry.nPathLen = nPathLen; + rEntry.sPath = sLOCPath; + } - if ( rEntry.nPathLen == -1 ) // the file was created + // the method can be reset for internal use so it is not checked + bBroken = rEntry.nVersion != nVersion + || rEntry.nFlag != nFlag + || rEntry.nTime != nTime + || rEntry.nPathLen != nPathLen + || !rEntry.sPath.equals( sLOCPath ); + } + catch(::std::bad_alloc &) { - rEntry.nPathLen = nPathLen; - rEntry.sPath = sLOCPath; + bBroken = sal_True; } - // the method can be reset for internal use so it is not checked - sal_Bool bBroken = rEntry.nVersion != nVersion - || rEntry.nFlag != nFlag - || rEntry.nTime != nTime - || rEntry.nPathLen != nPathLen - || !rEntry.sPath.equals( sLOCPath ); - if ( bBroken && !bRecoveryMode ) throw ZipIOException( OUString( RTL_CONSTASCII_USTRINGPARAM( "The stream seems to be broken!" ) ), Reference< XInterface >() ); |