diff options
author | Caolán McNamara <caolanm@redhat.com> | 2011-07-29 10:53:34 +0100 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2011-07-29 10:56:42 +0100 |
commit | f1346a0daee460c5aa4c3f13c7122785f5c41a36 (patch) | |
tree | aa9553a8d1e4058cc69f2ce833f0ded46c57baa5 /svtools | |
parent | 8291b5884c1c4c5278473886cdf1bb0f022aac99 (diff) |
check that reads succeeded
Diffstat (limited to 'svtools')
-rw-r--r-- | svtools/source/filter/wmf/winwmf.cxx | 62 | ||||
-rw-r--r-- | svtools/source/filter/wmf/wmf.cxx | 17 |
2 files changed, 50 insertions, 29 deletions
diff --git a/svtools/source/filter/wmf/winwmf.cxx b/svtools/source/filter/wmf/winwmf.cxx index 8ca9c0ac6d19..f9700816e2f8 100644 --- a/svtools/source/filter/wmf/winwmf.cxx +++ b/svtools/source/filter/wmf/winwmf.cxx @@ -1000,14 +1000,17 @@ void WMFReader::ReadRecordParams( sal_uInt16 nFunc ) sal_Bool WMFReader::ReadHeader(WMF_APMFILEHEADER *pAPMHeader) { - Rectangle aPlaceableBound; - sal_uInt32 nl, nStrmPos = pWMF->Tell(); + sal_Size nStrmPos = pWMF->Tell(); + sal_uInt32 nPlaceableMetaKey(0); // Einlesen des METAFILEHEADER, falls vorhanden - *pWMF >> nl; + *pWMF >> nPlaceableMetaKey; + if (!pWMF->good()) + return false; - Size aWMFSize; - if ( nl == 0x9ac6cdd7L ) + Rectangle aPlaceableBound; + + if (nPlaceableMetaKey == 0x9ac6cdd7L) { sal_Int16 nVal; @@ -1015,10 +1018,14 @@ sal_Bool WMFReader::ReadHeader(WMF_APMFILEHEADER *pAPMHeader) pWMF->SeekRel(2); // BoundRect - *pWMF >> nVal; aPlaceableBound.Left() = nVal; - *pWMF >> nVal; aPlaceableBound.Top() = nVal; - *pWMF >> nVal; aPlaceableBound.Right() = nVal; - *pWMF >> nVal; aPlaceableBound.Bottom() = nVal; + *pWMF >> nVal; + aPlaceableBound.Left() = nVal; + *pWMF >> nVal; + aPlaceableBound.Top() = nVal; + *pWMF >> nVal; + aPlaceableBound.Right() = nVal; + *pWMF >> nVal; + aPlaceableBound.Bottom() = nVal; // inch *pWMF >> nUnitsPerInch; @@ -1031,22 +1038,23 @@ sal_Bool WMFReader::ReadHeader(WMF_APMFILEHEADER *pAPMHeader) } else { - nUnitsPerInch = (pAPMHeader!=NULL?pAPMHeader->inch:96); - pWMF->Seek( nStrmPos + 18 ); // set the streampos to the start of the the metaactions - GetPlaceableBound( aPlaceableBound, pWMF ); - pWMF->Seek( nStrmPos ); - if (pAPMHeader!=NULL) { - // #n417818#: If we have an external header then overwrite the bounds! - aPlaceableBound=Rectangle(pAPMHeader->left*567*nUnitsPerInch/1440/1000, - pAPMHeader->top*567*nUnitsPerInch/1440/1000, - pAPMHeader->right*567*nUnitsPerInch/1440/1000, - pAPMHeader->bottom*567*nUnitsPerInch/1440/1000); - } + nUnitsPerInch = (pAPMHeader!=NULL?pAPMHeader->inch:96); + pWMF->Seek( nStrmPos + 18 ); // set the streampos to the start of the the metaactions + GetPlaceableBound( aPlaceableBound, pWMF ); + pWMF->Seek( nStrmPos ); + if (pAPMHeader!=NULL) + { + // #n417818#: If we have an external header then overwrite the bounds! + aPlaceableBound=Rectangle(pAPMHeader->left*567*nUnitsPerInch/1440/1000, + pAPMHeader->top*567*nUnitsPerInch/1440/1000, + pAPMHeader->right*567*nUnitsPerInch/1440/1000, + pAPMHeader->bottom*567*nUnitsPerInch/1440/1000); + } } pOut->SetUnitsPerInch( nUnitsPerInch ); pOut->SetWinOrg( aPlaceableBound.TopLeft() ); - aWMFSize = Size( labs( aPlaceableBound.GetWidth() ), labs( aPlaceableBound.GetHeight() ) ); + Size aWMFSize( labs( aPlaceableBound.GetWidth() ), labs( aPlaceableBound.GetHeight() ) ); pOut->SetWinExt( aWMFSize ); Size aDevExt( 10000, 10000 ); @@ -1060,12 +1068,14 @@ sal_Bool WMFReader::ReadHeader(WMF_APMFILEHEADER *pAPMHeader) pOut->SetDevExt( aDevExt ); // Einlesen des METAHEADER - *pWMF >> nl; // Typ und Headergroesse - - if( nl != 0x00090001 ) + sal_uInt32 nMetaKey(0); + *pWMF >> nMetaKey; // Typ und Headergroesse + if (!pWMF->good()) + return false; + if (nMetaKey != 0x00090001) { pWMF->SetError( SVSTREAM_FILEFORMAT_ERROR ); - return sal_False; + return false; } pWMF->SeekRel( 2 ); // Version (von Windows) @@ -1074,7 +1084,7 @@ sal_Bool WMFReader::ReadHeader(WMF_APMFILEHEADER *pAPMHeader) pWMF->SeekRel( 4 ); // MaxRecord (Groesse des groessten Records in Words) pWMF->SeekRel( 2 ); // NoParameters (Unused - return sal_True; + return pWMF->good(); } void WMFReader::ReadWMF(WMF_APMFILEHEADER *pAPMHeader) diff --git a/svtools/source/filter/wmf/wmf.cxx b/svtools/source/filter/wmf/wmf.cxx index 03923ddc508a..479ec5b30f86 100644 --- a/svtools/source/filter/wmf/wmf.cxx +++ b/svtools/source/filter/wmf/wmf.cxx @@ -33,6 +33,7 @@ #include "emfwr.hxx" #include "wmfwr.hxx" #include <svtools/wmf.hxx> +#include <comphelper/scopeguard.hxx> // ----------------------------------------------------------------------------- @@ -62,13 +63,23 @@ sal_Bool ConvertWMFToGDIMetaFile( SvStream & rStreamWMF, GDIMetaFile & rGDIMetaF sal_Bool ReadWindowMetafile( SvStream& rStream, GDIMetaFile& rMTF, FilterConfigItem* pFilterConfigItem ) { - sal_uInt32 nMetaType; + sal_uInt32 nMetaType(0); sal_uInt32 nOrgPos = rStream.Tell(); + sal_uInt16 nOrigNumberFormat = rStream.GetNumberFormatInt(); rStream.SetNumberFormatInt( NUMBERFORMAT_INT_LITTLEENDIAN ); + //exception-safe reset nOrigNumberFormat at end of scope + const ::comphelper::ScopeGuard aScopeGuard( + boost::bind(&SvStream::SetNumberFormatInt, ::boost::ref(rStream), + nOrigNumberFormat)); + rStream.Seek( 0x28 ); rStream >> nMetaType; rStream.Seek( nOrgPos ); + + if (!rStream.good()) + return false; + if ( nMetaType == 0x464d4520 ) { if ( EnhWMFReader( rStream, rMTF, NULL ).ReadEnhWMF() == sal_False ) @@ -78,8 +89,8 @@ sal_Bool ReadWindowMetafile( SvStream& rStream, GDIMetaFile& rMTF, FilterConfigI { WMFReader( rStream, rMTF, pFilterConfigItem ).ReadWMF(); } - rStream.SetNumberFormatInt( nOrigNumberFormat ); - return !rStream.GetError(); + + return rStream.good(); } // ----------------------------------------------------------------------------- |