Commits

Anonymous committed f0e7d5a Merge

contextmenu1: merge with DEV300_m95

Comments (0)

Files changed (270)

 2c70ae736e88ce4d9e9f0ffa08952f1987924bcd DEV300_m93
 a8b599672831a104faa85ad5ece8d67b4b0123ea OOO330_m15
 6a2043940003c27c523e35a582335d2982f6ef5f DEV300_m94
+f429027dae12ecc8b3fa76d5517525e29fb07ca0 OOO330_m16
+12b46f9bb0ec4dafb42b3bec984c096dc9209374 OOO330_m17
+41b0797e09ed77cf6b719fe7c39119d682d24749 DEV300_m95

basegfx/source/curve/b2dcubicbezier.cxx

 		// calculate the x-extrema parameters by zeroing first x-derivative
 		// of the cubic bezier's parametric formula, which results in a
 		// quadratic equation: dBezier/dt = t*t*fAX - 2*t*fBX + fCX
-		const B2DPoint aRelativeEndPoint(maEndPoint-maStartPoint);
-		const double fAX = 3 * (maControlPointA.getX() - maControlPointB.getX()) + aRelativeEndPoint.getX();
-		const double fBX = 2 * maControlPointA.getX() - maControlPointB.getX() - maStartPoint.getX();
-		double fCX(maControlPointA.getX() - maStartPoint.getX());
+		const B2DPoint aControlDiff( maControlPointA - maControlPointB );
+		double fCX = maControlPointA.getX() - maStartPoint.getX();
+		const double fBX = fCX + aControlDiff.getX();
+		const double fAX = 3 * aControlDiff.getX() + (maEndPoint.getX() - maStartPoint.getX());
 
 		if(fTools::equalZero(fCX))
 		{
 			{
 				const double fS = sqrt(fD);
 				// calculate both roots (avoiding a numerically unstable subtraction)
-				const double fQ = -(fBX + ((fBX >= 0) ? +fS : -fS));
+				const double fQ = fBX + ((fBX >= 0) ? +fS : -fS);
 				impCheckExtremumResult(fQ / fAX, rResults);
-				if( fD > 0.0 ) // ignore root multiplicity
+				if( !fTools::equalZero(fS) ) // ignore root multiplicity
 					impCheckExtremumResult(fCX / fQ, rResults);
 			}
 		}
 		}
 
 		// calculate the y-extrema parameters by zeroing first y-derivative
-		const double fAY = 3 * (maControlPointA.getY() - maControlPointB.getY()) + aRelativeEndPoint.getY();
-		const double fBY = 2 * maControlPointA.getY() - maControlPointB.getY() - maStartPoint.getY();
-		double fCY(maControlPointA.getY() - maStartPoint.getY());
+		double fCY = maControlPointA.getY() - maStartPoint.getY();
+		const double fBY = fCY + aControlDiff.getY();
+		const double fAY = 3 * aControlDiff.getY() + (maEndPoint.getY() - maStartPoint.getY());
 
 		if(fTools::equalZero(fCY))
 		{
 		{
 			// derivative is polynomial of order 2 => use binomial formula
 			const double fD = fBY*fBY - fAY*fCY;
-			if( fD >= 0 )
+			if( fD >= 0.0 )
 			{
 				const double fS = sqrt(fD);
 				// calculate both roots (avoiding a numerically unstable subtraction)
-				const double fQ = -(fBY + ((fBY >= 0) ? +fS : -fS));
+				const double fQ = fBY + ((fBY >= 0) ? +fS : -fS);
 				impCheckExtremumResult(fQ / fAY, rResults);
-				if( fD > 0.0 ) // ignore root multiplicity, TODO: use equalZero() instead?
+				if( !fTools::equalZero(fS) ) // ignore root multiplicity
 					impCheckExtremumResult(fCY / fQ, rResults);
 			}
 		}

basegfx/source/polygon/b2dtrapezoid.cxx

                                         if(splitEdgeAtGivenPoint(aLeft, *pNewLeft, aCurrent))
                                         {
     									    maNewPoints.push_back(pNewLeft);
+									        bDone = true;
                                         }
 										else
 										{
                                         if(splitEdgeAtGivenPoint(aRight, *pNewRight, aCurrent))
                                         {
     									    maNewPoints.push_back(pNewRight);
+									        bDone = true;
                                         }
 										else
 										{
 											delete pNewRight;
 										}
-    									
-									    bDone = true;
 								    }
                                 }
 

comphelper/inc/comphelper/docpasswordhelper.hxx

 #ifndef COMPHELPER_DOCPASSWORDHELPR_HXX
 #define COMPHELPER_DOCPASSWORDHELPR_HXX
 
+#include <com/sun/star/beans/NamedValue.hpp>
 #include "comphelper/comphelperdllapi.h"
 #include <vector>
 #include "comphelper/docpasswordrequest.hxx"
 /** Base class for a password verifier used by the DocPasswordHelper class
     below.
 
-    Users have to implement the virtual function and pass an instance of the
+    Users have to implement the virtual functions and pass an instance of the
     verifier to one of the password request functions.
  */
 class COMPHELPER_DLLPUBLIC IDocPasswordVerifier
 
     /** Will be called everytime a password needs to be verified.
 
+        @param rPassword
+            The password to be verified
+
+        @param o_rEncryptionData
+            Output parameter, that is filled with the EncryptionData generated
+            from the password. The data is filled only if the validation was
+            successful.
+
         @return  The result of the verification.
             - DocPasswordVerifierResult_OK, if and only if the passed password
               is valid and can be used to process the related document.
               occured while password verification. The password request loop
               will be aborted.
      */
-    virtual DocPasswordVerifierResult verifyPassword( const ::rtl::OUString& rPassword ) = 0;
+    virtual DocPasswordVerifierResult verifyPassword( const ::rtl::OUString& rPassword, ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue >& o_rEncryptionData ) = 0;
+
+    /** Will be called everytime an encryption data needs to be verified.
+
+        @param rEncryptionData
+            The data will be validated
+
+        @return  The result of the verification.
+            - DocPasswordVerifierResult_OK, if and only if the passed encryption data
+              is valid and can be used to process the related document.
+            - DocPasswordVerifierResult_WRONG_PASSWORD, if the encryption data is
+              wrong.
+            - DocPasswordVerifierResult_ABORT, if an unrecoverable error
+              occured while data verification. The password request loop
+              will be aborted.
+     */
+    virtual DocPasswordVerifierResult verifyEncryptionData( const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue >& o_rEncryptionData ) = 0;
 
 };
 
  
     // ------------------------------------------------------------------------
 
+    /** This helper function generates a random sequence of bytes of
+        requested length.
+      */
+
+    static ::com::sun::star::uno::Sequence< sal_Int8 > GenerateRandomByteSequence(
+                sal_Int32 nLength );
+
+    // ------------------------------------------------------------------------
+
+    /** This helper function generates a byte sequence representing the
+        key digest value used by MSCodec_Std97 codec.
+      */
+
+    static ::com::sun::star::uno::Sequence< sal_Int8 > GenerateStd97Key(
+                const ::rtl::OUString& aPassword,
+                const ::com::sun::star::uno::Sequence< sal_Int8 >& aDocId );
+
+    // ------------------------------------------------------------------------
+
+    /** This helper function generates a byte sequence representing the
+        key digest value used by MSCodec_Std97 codec.
+      */
+
+    static ::com::sun::star::uno::Sequence< sal_Int8 > GenerateStd97Key(
+                const sal_uInt16 pPassData[16],
+                const ::com::sun::star::uno::Sequence< sal_Int8 >& aDocId );
+
+    // ------------------------------------------------------------------------
+
     /** This helper function tries to request and verify a password to load a
         protected document.
 
             passed password verifier. If empty, no valid password has been
             found, or the user has chossen to cancel password input.
      */
-    static ::rtl::OUString requestAndVerifyDocPassword(
+    static ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue > requestAndVerifyDocPassword(
                             IDocPasswordVerifier& rVerifier,
+                            const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue >& rMediaEncData,
                             const ::rtl::OUString& rMediaPassword,
                             const ::com::sun::star::uno::Reference<
                                 ::com::sun::star::task::XInteractionHandler >& rxInteractHandler,
             passed password verifier. If empty, no valid password has been
             found, or the user has chossen to cancel password input.
      */
-    static ::rtl::OUString requestAndVerifyDocPassword(
+    static ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue > requestAndVerifyDocPassword(
                             IDocPasswordVerifier& rVerifier,
                             MediaDescriptor& rMediaDesc,
                             DocPasswordRequestType eRequestType,

comphelper/inc/comphelper/mediadescriptor.hxx

         static const ::rtl::OUString& PROP_DEEPDETECTION();
         static const ::rtl::OUString& PROP_DETECTSERVICE();
         static const ::rtl::OUString& PROP_DOCUMENTSERVICE();
+        static const ::rtl::OUString& PROP_ENCRYPTIONDATA();
         static const ::rtl::OUString& PROP_EXTENSION();
         static const ::rtl::OUString& PROP_FILENAME();
         static const ::rtl::OUString& PROP_FILTERNAME();

comphelper/inc/comphelper/storagehelper.hxx

 #include <com/sun/star/lang/XSingleServiceFactory.hpp>
 #include <com/sun/star/embed/XStorage.hpp>
 #include <com/sun/star/embed/ElementModes.hpp>
+#include <com/sun/star/beans/NamedValue.hpp>
 #include <com/sun/star/io/XInputStream.hpp>
 #include <com/sun/star/io/XOutputStream.hpp>
 #include <com/sun/star/io/XStream.hpp>
 #define ZIP_STORAGE_FORMAT_STRING		::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ZipFormat" ) )
 #define OFOPXML_STORAGE_FORMAT_STRING	::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "OFOPXMLFormat" ) )
 
+#define PACKAGE_ENCRYPTIONDATA_SHA1UTF8   ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "PackageSHA1UTF8EncryptionKey" ) )
+#define PACKAGE_ENCRYPTIONDATA_SHA1MS1252 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "PackageSHA1MS1252EncryptionKey" ) )
+
 namespace comphelper {
 
 class COMPHELPER_DLLPUBLIC OStorageHelper
 							= ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >() )
 		throw ( ::com::sun::star::uno::Exception );
 
-	static void SetCommonStoragePassword(
+	static void SetCommonStorageEncryptionData(
 			const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& xStorage,
-			const ::rtl::OUString& aPass )
+			const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue >& aEncryptionData )
 		throw ( ::com::sun::star::uno::Exception );
 
 	// the following method supports only storages of OOo formats
             sal_Bool bRepairStorage = sal_False )
 		throw ( ::com::sun::star::uno::Exception );
 
+    static ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue >
+        CreatePackageEncryptionData( const ::rtl::OUString& aPassword );
+
     static sal_Bool IsValidZipEntryFileName( const ::rtl::OUString& aName, sal_Bool bSlashAllowed );
     static sal_Bool IsValidZipEntryFileName( const sal_Unicode *pChar, sal_Int32 nLength, sal_Bool bSlashAllowed );
 

comphelper/source/misc/docpasswordhelper.cxx

 {
     uno::Sequence< beans::PropertyValue > aResult;
 
-    uno::Sequence< sal_Int8 > aSalt( 16 );
+    uno::Sequence< sal_Int8 > aSalt = GenerateRandomByteSequence( 16 );
     sal_Int32 nCount = 1024;
 
-    TimeValue aTime;
-    osl_getSystemTime( &aTime );
-    rtlRandomPool aRandomPool = rtl_random_createPool ();
-    rtl_random_addBytes ( aRandomPool, &aTime, 8 ); 
-
-    rtl_random_getBytes ( aRandomPool, aSalt.getArray(), 16 );
-
     uno::Sequence< sal_Int8 > aNewHash = GeneratePBKDF2Hash( aPassword, aSalt, nCount, 16 );
     if ( aNewHash.getLength() )
     {
         aResult[3].Value <<= aNewHash;
     }
 
-    // Clean up random pool memory
-    rtl_random_destroyPool ( aRandomPool );
-
     return aResult;
 }
 
 }
  
 // ============================================================================
+/*static*/ uno::Sequence< sal_Int8 > DocPasswordHelper::GenerateRandomByteSequence( sal_Int32 nLength )
+{
+    uno::Sequence< sal_Int8 > aResult( nLength );
 
-/*static*/ OUString DocPasswordHelper::requestAndVerifyDocPassword(
+    TimeValue aTime;
+    osl_getSystemTime( &aTime );
+    rtlRandomPool aRandomPool = rtl_random_createPool ();
+    rtl_random_addBytes ( aRandomPool, &aTime, 8 ); 
+    rtl_random_getBytes ( aRandomPool, aResult.getArray(), nLength );
+    rtl_random_destroyPool ( aRandomPool );
+
+    return aResult;
+}
+
+
+// ============================================================================
+/*static*/ uno::Sequence< sal_Int8 > DocPasswordHelper::GenerateStd97Key( const ::rtl::OUString& aPassword, const uno::Sequence< sal_Int8 >& aDocId )
+{
+    uno::Sequence< sal_Int8 > aResultKey;
+    if ( aPassword.getLength() && aDocId.getLength() == 16 )
+    {
+        sal_uInt16 pPassData[16];
+        rtl_zeroMemory( pPassData, sizeof(pPassData) );
+
+        sal_Int32 nPassLen = ::std::min< sal_Int32 >( aPassword.getLength(), 15 );
+        rtl_copyMemory( pPassData, aPassword.getStr(), nPassLen * sizeof(pPassData[0]) );
+
+        aResultKey = GenerateStd97Key( pPassData, aDocId );
+    }
+
+    return aResultKey;
+}
+
+// ============================================================================
+/*static*/ uno::Sequence< sal_Int8 > DocPasswordHelper::GenerateStd97Key( const sal_uInt16 pPassData[16], const uno::Sequence< sal_Int8 >& aDocId )
+{
+    uno::Sequence< sal_Int8 > aResultKey;
+    if ( pPassData[0] && aDocId.getLength() == 16 )
+    {
+        sal_uInt8 pKeyData[64];
+        rtl_zeroMemory( pKeyData, sizeof(pKeyData) );
+
+        sal_Int32 nInd = 0;
+
+        // Fill PassData into KeyData.
+        for ( nInd = 0; nInd < 16 && pPassData[nInd]; nInd++)
+        {
+            pKeyData[2*nInd] = sal::static_int_cast< sal_uInt8 >( (pPassData[nInd] >> 0) & 0xff );
+            pKeyData[2*nInd + 1] = sal::static_int_cast< sal_uInt8 >( (pPassData[nInd] >> 8) & 0xff );
+        }
+
+        pKeyData[2*nInd] = 0x80;
+        pKeyData[56] = sal::static_int_cast< sal_uInt8 >( nInd << 4 );
+
+        // Fill raw digest of KeyData into KeyData.
+        rtlDigest hDigest = rtl_digest_create ( rtl_Digest_AlgorithmMD5 );
+        (void)rtl_digest_updateMD5 (
+            hDigest, pKeyData, sizeof(pKeyData));
+        (void)rtl_digest_rawMD5 (
+            hDigest, pKeyData, RTL_DIGEST_LENGTH_MD5);
+
+        // Update digest with KeyData and Unique.
+        for ( nInd = 0; nInd < 16; nInd++ )
+        {
+            rtl_digest_updateMD5( hDigest, pKeyData, 5 );
+            rtl_digest_updateMD5( hDigest, (const sal_uInt8*)aDocId.getConstArray(), aDocId.getLength() );
+        }
+
+        // Update digest with padding.
+        pKeyData[16] = 0x80;
+        rtl_zeroMemory( pKeyData + 17, sizeof(pKeyData) - 17 );
+        pKeyData[56] = 0x80;
+        pKeyData[57] = 0x0a;
+
+        rtl_digest_updateMD5( hDigest, &(pKeyData[16]), sizeof(pKeyData) - 16 );
+
+        // Fill raw digest of above updates
+        aResultKey.realloc( RTL_DIGEST_LENGTH_MD5 );
+        rtl_digest_rawMD5 ( hDigest, (sal_uInt8*)aResultKey.getArray(), aResultKey.getLength() );
+
+        // Erase KeyData array and leave.
+        rtl_zeroMemory( pKeyData, sizeof(pKeyData) );
+    }
+
+    return aResultKey;
+}
+
+// ============================================================================
+
+/*static*/ ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue > DocPasswordHelper::requestAndVerifyDocPassword(
         IDocPasswordVerifier& rVerifier,
+        const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue >& rMediaEncData,
         const OUString& rMediaPassword,
         const Reference< XInteractionHandler >& rxInteractHandler,
         const OUString& rDocumentName,
         const ::std::vector< OUString >* pDefaultPasswords,
         bool* pbIsDefaultPassword )
 {
-    OUString aPassword;
+    ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue > aEncData;
     DocPasswordVerifierResult eResult = DocPasswordVerifierResult_WRONG_PASSWORD;
 
     // first, try provided default passwords
     {
         for( ::std::vector< OUString >::const_iterator aIt = pDefaultPasswords->begin(), aEnd = pDefaultPasswords->end(); (eResult == DocPasswordVerifierResult_WRONG_PASSWORD) && (aIt != aEnd); ++aIt )
         {
-            aPassword = *aIt;
-            OSL_ENSURE( aPassword.getLength() > 0, "DocPasswordHelper::requestAndVerifyDocPassword - unexpected empty default password" );
-            if( aPassword.getLength() > 0 )
+            OSL_ENSURE( aIt->getLength() > 0, "DocPasswordHelper::requestAndVerifyDocPassword - unexpected empty default password" );
+            if( aIt->getLength() > 0 )
             {
-                eResult = rVerifier.verifyPassword( aPassword );
+                eResult = rVerifier.verifyPassword( *aIt, aEncData );
                 if( pbIsDefaultPassword )
                     *pbIsDefaultPassword = eResult == DocPasswordVerifierResult_OK;
             }
         }
     }
 
+    // try media encryption data (skip, if result is OK or ABORT)
+    if( eResult == DocPasswordVerifierResult_WRONG_PASSWORD )
+    {
+        if( rMediaEncData.getLength() > 0 )
+        {
+            eResult = rVerifier.verifyEncryptionData( rMediaEncData );
+            if( eResult == DocPasswordVerifierResult_OK )
+                aEncData = rMediaEncData;
+        }
+    }
+
     // try media password (skip, if result is OK or ABORT)
     if( eResult == DocPasswordVerifierResult_WRONG_PASSWORD )
     {
-        aPassword = rMediaPassword;
-        if( aPassword.getLength() > 0 )
-            eResult = rVerifier.verifyPassword( aPassword );
+        if( rMediaPassword.getLength() > 0 )
+            eResult = rVerifier.verifyPassword( rMediaPassword, aEncData );
     }
 
     // request a password (skip, if result is OK or ABORT)
             rxInteractHandler->handle( xRequest );
             if( pRequest->isPassword() )
             {
-                aPassword = pRequest->getPassword();
-                if( aPassword.getLength() > 0 )
-                    eResult = rVerifier.verifyPassword( aPassword );
+                if( pRequest->getPassword().getLength() > 0 )
+                    eResult = rVerifier.verifyPassword( pRequest->getPassword(), aEncData );
             }
             else
             {
     {
     }
 
-    return (eResult == DocPasswordVerifierResult_OK) ? aPassword : OUString();
+    return (eResult == DocPasswordVerifierResult_OK) ? aEncData : uno::Sequence< beans::NamedValue >();
 }
 
-/*static*/ OUString DocPasswordHelper::requestAndVerifyDocPassword(
+/*static*/ ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue > DocPasswordHelper::requestAndVerifyDocPassword(
         IDocPasswordVerifier& rVerifier,
         MediaDescriptor& rMediaDesc,
         DocPasswordRequestType eRequestType,
         const ::std::vector< OUString >* pDefaultPasswords )
 {
+    uno::Sequence< beans::NamedValue > aMediaEncData = rMediaDesc.getUnpackedValueOrDefault(
+        MediaDescriptor::PROP_ENCRYPTIONDATA(), uno::Sequence< beans::NamedValue >() );
     OUString aMediaPassword = rMediaDesc.getUnpackedValueOrDefault(
         MediaDescriptor::PROP_PASSWORD(), OUString() );
     Reference< XInteractionHandler > xInteractHandler = rMediaDesc.getUnpackedValueOrDefault(
         MediaDescriptor::PROP_URL(), OUString() );
 
     bool bIsDefaultPassword = false;
-    OUString aPassword = requestAndVerifyDocPassword(
-        rVerifier, aMediaPassword, xInteractHandler, aDocumentName, eRequestType, pDefaultPasswords, &bIsDefaultPassword );
+    uno::Sequence< beans::NamedValue > aEncryptionData = requestAndVerifyDocPassword(
+        rVerifier, aMediaEncData, aMediaPassword, xInteractHandler, aDocumentName, eRequestType, pDefaultPasswords, &bIsDefaultPassword );
+
+    rMediaDesc.erase( MediaDescriptor::PROP_PASSWORD() );
+    rMediaDesc.erase( MediaDescriptor::PROP_ENCRYPTIONDATA() );
 
     // insert valid password into media descriptor (but not a default password)
-    if( (aPassword.getLength() > 0) && !bIsDefaultPassword )
-        rMediaDesc[ MediaDescriptor::PROP_PASSWORD() ] <<= aPassword;
+    if( (aEncryptionData.getLength() > 0) && !bIsDefaultPassword )
+        rMediaDesc[ MediaDescriptor::PROP_ENCRYPTIONDATA() ] <<= aEncryptionData;
 
-    return aPassword;
+    return aEncryptionData;
 }
 
 // ============================================================================

comphelper/source/misc/mediadescriptor.cxx

     return sProp;
 }
 
+const ::rtl::OUString& MediaDescriptor::PROP_ENCRYPTIONDATA()
+{
+    static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("EncryptionData"));
+    return sProp;
+}
+
 const ::rtl::OUString& MediaDescriptor::PROP_EXTENSION()
 {
     static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("Extension"));

comphelper/source/misc/storagehelper.cxx

 // MARKER(update_precomp.py): autogen include statement, do not remove
 #include "precompiled_comphelper.hxx"
 #include <com/sun/star/embed/ElementModes.hpp>
-#include <com/sun/star/embed/XEncryptionProtectedSource.hpp>
+#include <com/sun/star/embed/XEncryptionProtectedSource2.hpp>
 #include <com/sun/star/ucb/XSimpleFileAccess.hpp>
 #include <com/sun/star/beans/XPropertySet.hpp>
 #include <com/sun/star/beans/PropertyValue.hpp>
+#include <com/sun/star/beans/NamedValue.hpp>
 #include <com/sun/star/beans/IllegalTypeException.hpp>
 
+#include <rtl/digest.h>
+
 #include <ucbhelper/content.hxx>
 
 #include <comphelper/fileformat.h>
 }
 
 // ----------------------------------------------------------------------
-void OStorageHelper::SetCommonStoragePassword(
+void OStorageHelper::SetCommonStorageEncryptionData(
 			const uno::Reference< embed::XStorage >& xStorage,
-			const ::rtl::OUString& aPass )
+			const uno::Sequence< beans::NamedValue >& aEncryptionData )
 	throw ( uno::Exception )
 {
-	uno::Reference< embed::XEncryptionProtectedSource > xEncrSet( xStorage, uno::UNO_QUERY );
+	uno::Reference< embed::XEncryptionProtectedSource2 > xEncrSet( xStorage, uno::UNO_QUERY );
 	if ( !xEncrSet.is() )
 		throw io::IOException(); // TODO
 
-	xEncrSet->setEncryptionPassword( aPass );
+	xEncrSet->setEncryptionData( aEncryptionData );
 }
 
 // ----------------------------------------------------------------------
 }
 
 // ----------------------------------------------------------------------
+uno::Sequence< beans::NamedValue > OStorageHelper::CreatePackageEncryptionData( const ::rtl::OUString& aPassword )
+{
+    // TODO/LATER: Should not the method be part of DocPasswordHelper?
+    uno::Sequence< beans::NamedValue > aEncryptionData;
+    if ( aPassword.getLength() )
+    {
+        // MS_1252 encoding was used for SO60 document format password encoding,
+        // this encoding supports only a minor subset of nonascii characters,
+        // but for compatibility reasons it has to be used for old document formats
+        aEncryptionData.realloc( 2 );
+        aEncryptionData[0].Name = PACKAGE_ENCRYPTIONDATA_SHA1UTF8;
+        aEncryptionData[1].Name = PACKAGE_ENCRYPTIONDATA_SHA1MS1252;
+
+        rtl_TextEncoding pEncoding[2] = { RTL_TEXTENCODING_UTF8, RTL_TEXTENCODING_MS_1252 };
+
+        for ( sal_Int32 nInd = 0; nInd < 2; nInd++ )
+        {
+            ::rtl::OString aByteStrPass = ::rtl::OUStringToOString( aPassword, pEncoding[nInd] );
+
+            sal_uInt8 pBuffer[RTL_DIGEST_LENGTH_SHA1];
+            rtlDigestError nError = rtl_digest_SHA1( aByteStrPass.getStr(),
+                                                    aByteStrPass.getLength(),
+                                                    pBuffer,
+                                                    RTL_DIGEST_LENGTH_SHA1 );
+
+            if ( nError != rtl_Digest_E_None )
+            {
+                aEncryptionData.realloc( 0 );
+                break;
+            }
+
+            aEncryptionData[nInd].Value <<= uno::Sequence< sal_Int8 >( (sal_Int8*)pBuffer, RTL_DIGEST_LENGTH_SHA1 );
+        }
+    }
+
+    return aEncryptionData;
+}
+
+// ----------------------------------------------------------------------
 sal_Bool OStorageHelper::IsValidZipEntryFileName( const ::rtl::OUString& aName, sal_Bool bSlashAllowed )
 {
     return IsValidZipEntryFileName( aName.getStr(), aName.getLength(), bSlashAllowed );

configmgr/source/childaccess.cxx

             if (!Components::allLocales(locale)) {
                 // Find best match using an adaption of RFC 4647 lookup matching
                 // rules, removing "-" or "_" delimited segments from the end;
-                // defaults are the empty string locale, the "en-US" locale, the
-                // "en" locale, the first child (if any), or a nil value (even
+                // defaults are the "en-US" locale, the "en" locale, the empty
+                // string locale, the first child (if any), or a nil value (even
                 // though it may be illegal for the given property), in that
                 // order:
                 rtl::Reference< ChildAccess > child;
                     while (i > 0 && locale[i] != '-' && locale[i] != '_') {
                         --i;
                     }
+                    if (i == 0) {
+                        break;
+                    }
                     locale = locale.copy(0, i);
                 }
                 if (!child.is()) {
                         child = getChild(
                             rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("en")));
                         if (!child.is()) {
-                            std::vector< rtl::Reference< ChildAccess > > all(
-                                getAllChildren());
-                            if (!all.empty()) {
-                                child = all.front();
+                            child = getChild(rtl::OUString());
+                            if (!child.is()) {
+                                std::vector< rtl::Reference< ChildAccess > >
+                                    all(getAllChildren());
+                                if (!all.empty()) {
+                                    child = all.front();
+                                }
                             }
                         }
                     }
 
 
 KDE4_CFLAGS=""
-KDE4_LIBS=""
-MOC4="moc"
+KDE4_LIBS="/usr/lib64/kde4"
+MOC4="/usr/bin/moc-qt4"
 if test "$test_kde4" = "yes" -a "$ENABLE_KDE4" = "TRUE" ; then
    qt_incdirs="$QT4INC $QT4DIR /usr/include/qt4 /usr/include $x_includes"
    qt_libdirs="$QT4LIB /usr/lib $x_libraries"
 
-   kde_incdirs="/usr/include $x_includes"
+   kde_incdirs="/usr/include /usr/include/kde4 $x_includes"
    kde_libdirs="/usr/lib $x_libraries"
 
    if test "$build_cpu" = "x86_64" ; then

drawinglayer/source/primitive2d/metafileprimitive2d.cxx

             if(nPushFlags)
             {
                 OSL_ENSURE(maPropertyHolders.size(), "PropertyHolders: PUSH with no property holders (!)");
-                PropertyHolder* pNew = new PropertyHolder(*maPropertyHolders.back());
-                pNew->setPushFlags(nPushFlags);
-                maPropertyHolders.push_back(pNew);
+				if ( !maPropertyHolders.empty() )
+				{
+					PropertyHolder* pNew = new PropertyHolder(*maPropertyHolders.back());
+					pNew->setPushFlags(nPushFlags);
+					maPropertyHolders.push_back(pNew);
+				}
             }
         }
 
 
         PropertyHolder& Current()
         {
+			static PropertyHolder aDummy;
             OSL_ENSURE(maPropertyHolders.size(), "PropertyHolders: CURRENT with no property holders (!)");
-            return *maPropertyHolders.back();
+			return maPropertyHolders.empty() ? aDummy : *maPropertyHolders.back();
         }
 
         ~PropertyHolders()

editeng/inc/editeng/svxrtf.hxx

 inline SfxItemSet& SvxRTFParser::GetAttrSet()
 {
 	SvxRTFItemStackTypePtr pTmp;
-	if( bNewGroup || 0 == ( pTmp = aAttrStack.back()) )
+    if( bNewGroup || 0 == ( pTmp = aAttrStack.empty() ? 0 : aAttrStack.back()) )
 		pTmp = _GetAttrSet();
 	return pTmp->aAttrSet;
 }

editeng/source/items/flditem.cxx

 
 // -----------------------------------------------------------------------
 
+static void write_unicode( SvPersistStream & rStm, const String& rString )
+{
+	USHORT nL = rString.Len();
+	rStm << nL;
+	rStm.Write( rString.GetBuffer(), nL*sizeof(sal_Unicode) );
+}
+
+static void read_unicode( SvPersistStream & rStm, String& rString )
+{
+	USHORT nL = 0;
+	rStm >> nL;
+	if ( nL )
+	{
+		rString.AllocBuffer( nL );
+		rStm.Read( rString.GetBufferAccess(), nL*sizeof(sal_Unicode) );
+		rString.ReleaseBufferAccess( nL );
+	}
+}
+
 void SvxURLField::Load( SvPersistStream & rStm )
 {
-	USHORT nFormat;
-	sal_uInt32 nFrameMarker, nCharSetMarker;
-	long nUlongSize = (long)sizeof(sal_uInt32);
-	String aTmpURL;
+	USHORT nFormat = 0;
 
 	rStm >> nFormat;
-
-	// UNICODE: rStm >> aTmpURL;
-	rStm.ReadByteString(aTmpURL);
-
-	// UNICODE: rStm >> aRepresentation;
-	// read to a temp string first, read text encoding and
-	// convert later to stay compatible to fileformat
-	ByteString aTempString;
-	rtl_TextEncoding aTempEncoding = RTL_TEXTENCODING_MS_1252;  // #101493# Init for old documents
-	rStm.ReadByteString(aTempString);
-
-	rStm >> nFrameMarker;
-	if ( nFrameMarker == FRAME_MARKER )
-	{
-		// UNICODE: rStm >> aTargetFrame;
-		rStm.ReadByteString(aTargetFrame);
-
-		rStm >> nCharSetMarker;
-		if ( nCharSetMarker == CHARSET_MARKER )
-		{
-			USHORT nCharSet;
-			rStm >> nCharSet;
-
-			// remember encoding
-			aTempEncoding = (rtl_TextEncoding)nCharSet;
-		}
-		else
-			rStm.SeekRel( -nUlongSize );
-	}
-	else
-		rStm.SeekRel( -nUlongSize );
-
-	// now build representation string due to known encoding
-	aRepresentation = String(aTempString, aTempEncoding);
-
 	eFormat= (SvxURLFormat)nFormat;
 
-	// Relatives Speichern => Beim laden absolut machen.
-    DBG_ERROR("No BaseURL!");
-    // TODO/MBA: no BaseURL
-    aURL = INetURLObject::GetAbsURL( String(), aTmpURL );
+	read_unicode( rStm, aURL );
+	read_unicode( rStm, aRepresentation );
+	read_unicode( rStm, aTargetFrame );
 }
 
 // -----------------------------------------------------------------------
 
 void SvxURLField::Save( SvPersistStream & rStm )
 {
-	// Relatives Speichern der URL
-    DBG_ERROR("No BaseURL!");
-    // TODO/MBA: no BaseURL
-    String aTmpURL = INetURLObject::GetRelURL( String(), aURL );
-
 	rStm << (USHORT)eFormat;
 
-	// UNICODE: rStm << aTmpURL;
-	rStm.WriteByteString(aTmpURL);
-
-	// UNICODE: rStm << aRepresentation;
-	rStm.WriteByteString(aRepresentation);
-
-	rStm << FRAME_MARKER;
-
-	// UNICODE: rStm << aTargetFrame;
-	rStm.WriteByteString(aTargetFrame);
-
-	rStm << CHARSET_MARKER;
-
-	// #90477# rStm << (USHORT)GetStoreCharSet(gsl_getSystemTextEncoding(), rStm.GetVersion());
-	rStm << (USHORT)GetSOStoreTextEncoding(gsl_getSystemTextEncoding(), (sal_uInt16)rStm.GetVersion());
+	write_unicode( rStm, aURL );
+	write_unicode( rStm, aRepresentation );
+	write_unicode( rStm, aTargetFrame );
 }
 
 MetaAction* SvxURLField::createBeginComment() const
 
 void SvxAuthorField::Load( SvPersistStream & rStm )
 {
-	USHORT nType, nFormat;
+	USHORT nType = 0, nFormat = 0;
 
-	// UNICODE: rStm >> aName;
-	rStm.ReadByteString(aName);
-
-	// UNICODE: rStm >> aFirstName;
-	rStm.ReadByteString(aFirstName);
-
-	// UNICODE: rStm >> aShortName;
-	rStm.ReadByteString(aShortName);
+	read_unicode( rStm, aName );
+	read_unicode( rStm, aFirstName );
+	read_unicode( rStm, aShortName );
 
 	rStm >> nType;
 	rStm >> nFormat;
 
 void SvxAuthorField::Save( SvPersistStream & rStm )
 {
-	// UNICODE: rStm << aName;
-	rStm.WriteByteString(aName);
-
-	// UNICODE: rStm << aFirstName;
-	rStm.WriteByteString(aFirstName);
-
-	// UNICODE: rStm << aShortName;
-	rStm.WriteByteString(aShortName);
+	write_unicode( rStm, aName );
+	write_unicode( rStm, aFirstName );
+	write_unicode( rStm, aShortName );
 
 	rStm << (USHORT) eType;
 	rStm << (USHORT) eFormat;

editeng/source/misc/svxacorr.cxx

                     bRunNext = true;
             }
         }
-        else if ( cChar == '/' )
+        else if ( cChar == '/' && nEndPos > 1 && rTxt.Len() > (nEndPos - 1) )
         {
             // Remove the hardspace right before to avoid formatting URLs
             sal_Unicode cPrevChar = rTxt.GetChar( nEndPos - 1 );

editeng/source/rtf/rtfitem.cxx

 	RTF_CharTypeDef eCharType = NOTDEF_CHARTYPE;
 	USHORT nFontAlign;
 
-	int bChkStkPos = !bNewGroup && aAttrStack.back();
+	int bChkStkPos = !bNewGroup && !aAttrStack.empty();
 
 	while( bWeiter && IsParserWorking() )			// solange bekannte Attribute erkannt werden
 	{
 				if( !bChkStkPos )
 					break;
 
-				SvxRTFItemStackType* pAkt = aAttrStack.back();
+				SvxRTFItemStackType* pAkt = aAttrStack.empty() ? 0 : aAttrStack.back();
 				if( !pAkt || (pAkt->pSttNd->GetIdx() == pInsPos->GetNodeIdx() &&
 					pAkt->nSttCnt == pInsPos->GetCntIdx() ))
 					break;
 
 					// alle bis hierher gueltigen Attribute "setzen"
 					AttrGroupEnd();
-					pAkt = aAttrStack.back();  // can be changed after AttrGroupEnd!
+					pAkt = aAttrStack.empty() ? 0 : aAttrStack.back();  // can be changed after AttrGroupEnd!
 					pNew->aAttrSet.SetParent( pAkt ? &pAkt->aAttrSet : 0 );
 
 					aAttrStack.push_back( pNew );
 					nStyleNo = -1 == nTokenValue ? 0 : USHORT(nTokenValue);
 					// setze am akt. auf dem AttrStack stehenden Style die
 					// StyleNummer
-					SvxRTFItemStackType* pAkt = aAttrStack.back();
+					SvxRTFItemStackType* pAkt = aAttrStack.empty() ? 0 : aAttrStack.back();
 					if( !pAkt )
 						break;
 
 // pard / plain abarbeiten
 void SvxRTFParser::RTFPardPlain( int bPard, SfxItemSet** ppSet )
 {
-	if( !bNewGroup && aAttrStack.back() )	// not at the beginning of a new group
+	if( !bNewGroup && !aAttrStack.empty() )	// not at the beginning of a new group
 	{
-		SvxRTFItemStackType* pAkt = aAttrStack.back();
+        SvxRTFItemStackType* pAkt = aAttrStack.back();
 
 		int nLastToken = GetStackPtr(-1)->nTokenId;
 		int bNewStkEntry = TRUE;
 
 				// alle bis hierher gueltigen Attribute "setzen"
 				AttrGroupEnd();
-				pAkt = aAttrStack.back();  // can be changed after AttrGroupEnd!
+				pAkt = aAttrStack.empty() ? 0 : aAttrStack.back();  // can be changed after AttrGroupEnd!
 				pNew->aAttrSet.SetParent( pAkt ? &pAkt->aAttrSet : 0 );
 				aAttrStack.push_back( pNew );
 				pAkt = pNew;

editeng/source/rtf/svxrtf.cxx

 
 SvxRTFItemStackType* SvxRTFParser::_GetAttrSet( int bCopyAttr )
 {
-	SvxRTFItemStackType* pAkt = aAttrStack.back();
+    SvxRTFItemStackType* pAkt = aAttrStack.empty() ? 0 : aAttrStack.back();
 	SvxRTFItemStackType* pNew;
 	if( pAkt )
 		pNew = new SvxRTFItemStackType( *pAkt, *pInsPos, bCopyAttr );
 {
 	if( !aAttrStack.empty() )
 	{
-		SvxRTFItemStackType *pOld = aAttrStack.back();
+        SvxRTFItemStackType *pOld = aAttrStack.empty() ? 0 : aAttrStack.back();
 		aAttrStack.pop_back();
-		SvxRTFItemStackType *pAkt = aAttrStack.back();
+		SvxRTFItemStackType *pAkt = aAttrStack.empty() ? 0 : aAttrStack.back();
 
 		do {		// middle check loop
 			ULONG nOldSttNdIdx = pOld->pSttNd->GetIdx();
 
 						// alle bis hierher gueltigen Attribute "setzen"
 						AttrGroupEnd();
-						pAkt = aAttrStack.back();  // can be changed after AttrGroupEnd!
+                        pAkt = aAttrStack.empty() ? 0 : aAttrStack.back();  // can be changed after AttrGroupEnd!
 						pNew->aAttrSet.SetParent( pAkt ? &pAkt->aAttrSet : 0 );
 						aAttrStack.push_back( pNew );
 						pAkt = pNew;
 	// Is text wasn't inserted? (Get SttPos from the top of stack!)
 int	SvxRTFParser::IsAttrSttPos()
 {
-	SvxRTFItemStackType* pAkt = aAttrStack.back();
+    SvxRTFItemStackType* pAkt = aAttrStack.empty() ? 0 : aAttrStack.back();
 	return !pAkt || (pAkt->pSttNd->GetIdx() == pInsPos->GetNodeIdx() &&
 		pAkt->nSttCnt == pInsPos->GetCntIdx());
 }

extras/source/gallery/gallery_system/sg24.sdg

Binary file modified.

extras/source/gallery/gallery_system/sg24.sdv

Binary file modified.

extras/source/gallery/gallery_system/sg24.thm

Binary file modified.

filter/inc/filter/msfilter/mscodec.hxx

 #ifndef SVX_MSCODEC_HXX
 #define SVX_MSCODEC_HXX
 
-#include "rtl/cipher.h"
-#include "rtl/digest.h"
+#include <com/sun/star/uno/Sequence.hxx>
+#include <com/sun/star/beans/NamedValue.hpp>
+
+#include <rtl/cipher.h>
+#include <rtl/digest.h>
 #include "filter/msfilter/msfilterdllapi.h"
 
 namespace msfilter {
      */
     void                InitKey( const sal_uInt8 pnPassData[ 16 ] );
 
+    /** Initializes the algorithm with the encryption data.
+
+        @param aData
+            The sequence contains the necessary data to initialize
+            the codec.
+     */
+    sal_Bool                InitCodec( const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue >& aData );
+
+    /** Retrieves the encryption data
+
+        @return
+            The sequence contains the necessary data to initialize
+            the codec.
+     */
+    ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue > GetEncryptionData();
+
+
     /** Verifies the validity of the password using the passed key and hash.
 
         @precond
      */
     void                Skip( sal_Size nBytes );
 
-    // static -----------------------------------------------------------------
-
-    /** Calculates the 16-bit hash value for the given password.
-
-        The password data may be longer than 16 bytes. The array does not need
-        to be terminated with a NULL byte (but it can without invalidating the
-        result).
-     */
-    static sal_uInt16   GetHash( const sal_uInt8* pnPassData, sal_Size nSize );
-
 protected:
     sal_uInt8           mpnKey[ 16 ];   /// Encryption key.
     sal_Size            mnOffset;       /// Key offset.
     explicit            MSCodec_Std97();
                         ~MSCodec_Std97();
 
+    /** Initializes the algorithm with the encryption data.
+
+        @param aData
+            The sequence contains the necessary data to initialize
+            the codec.
+     */
+    sal_Bool                InitCodec( const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue >& aData );
+
+    /** Retrieves the encryption data
+
+        @return
+            The sequence contains the necessary data to initialize
+            the codec.
+     */
+    ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue > GetEncryptionData();
+
+
     /** Initializes the algorithm with the specified password and document ID.
 
         @param pPassData
             Wide character array containing the password. Must be zero
             terminated, which results in a maximum length of 15 characters.
-        @param pUnique
+        @param pDocId
             Unique document identifier read from or written to the file.
      */
     void                InitKey(
                             const sal_uInt16 pPassData[ 16 ],
-                            const sal_uInt8 pUnique[ 16 ] );
+                            const sal_uInt8 pDocId[ 16 ] );
 
     /** Verifies the validity of the password using the passed salt data.
 
 							sal_uInt8 pSaltData[16], 
 							sal_uInt8 pSaltDigest[16]);
 	
+    /* allows to get the unique document id from the codec
+     */
+    void                GetDocId( sal_uInt8 pDocId[16] );
+
+    void                GetDigestFromSalt( const sal_uInt8 pSaltData[16], sal_uInt8 pDigest[16] );
+
 private:
-    void                GetDigestFromSalt( const sal_uInt8 pSaltData[16], sal_uInt8 pDigest[16] );
+    void                InitKeyImpl(
+                            const sal_uInt8 pKeyData[64],
+                            const sal_uInt8 pDocId[16] );
+
 
 private:
                         MSFILTER_DLLPRIVATE MSCodec_Std97( const MSCodec_Std97& );
     rtlCipher           m_hCipher;
     rtlDigest           m_hDigest;
     sal_uInt8           m_pDigestValue[ RTL_DIGEST_LENGTH_MD5 ];
+    sal_uInt8           m_pDocId[16];
 };
 
 // ============================================================================

filter/source/graphicfilter/itiff/itiff.cxx

 		}
 		else if ( nPhotometricInterpretation == 2 && nSamplesPerPixel >= 3 )
 		{
-			ULONG nMinMax = nMinSampleValue * 255 / ( nMaxSampleValue - nMinSampleValue );
-			for ( nx = 0; nx < nImageWidth; nx++ )
+			if ( nMaxSampleValue > nMinSampleValue )
 			{
-				if ( nPlanes < 3 )
+				ULONG nMinMax = nMinSampleValue * 255 / ( nMaxSampleValue - nMinSampleValue );
+				for ( nx = 0; nx < nImageWidth; nx++ )
 				{
-					nRed = GetBits( pMap[ 0 ], ( nx * nSamplesPerPixel + 0 ) * nBitsPerSample, nBitsPerSample );
-					nGreen = GetBits( pMap[ 1 ], ( nx * nSamplesPerPixel + 1 ) * nBitsPerSample, nBitsPerSample );
-					nBlue = GetBits( pMap[ 2 ], ( nx * nSamplesPerPixel + 2 ) * nBitsPerSample, nBitsPerSample );
+					if ( nPlanes < 3 )
+					{
+						nRed = GetBits( pMap[ 0 ], ( nx * nSamplesPerPixel + 0 ) * nBitsPerSample, nBitsPerSample );
+						nGreen = GetBits( pMap[ 1 ], ( nx * nSamplesPerPixel + 1 ) * nBitsPerSample, nBitsPerSample );
+						nBlue = GetBits( pMap[ 2 ], ( nx * nSamplesPerPixel + 2 ) * nBitsPerSample, nBitsPerSample );
+					}
+					else
+					{
+						nRed = GetBits( pMap[ 0 ], nx * nBitsPerSample, nBitsPerSample );
+						nGreen = GetBits( pMap[ 1 ], nx * nBitsPerSample, nBitsPerSample );
+						nBlue = GetBits( pMap[ 2 ], nx * nBitsPerSample, nBitsPerSample );
+					}
+					pAcc->SetPixel( nY, nx, Color( (BYTE)( nRed - nMinMax ), (BYTE)( nGreen - nMinMax ), (BYTE)(nBlue - nMinMax) ) );
 				}
-				else
-				{
-					nRed = GetBits( pMap[ 0 ], nx * nBitsPerSample, nBitsPerSample );
-					nGreen = GetBits( pMap[ 1 ], nx * nBitsPerSample, nBitsPerSample );
-					nBlue = GetBits( pMap[ 2 ], nx * nBitsPerSample, nBitsPerSample );
-				}
-				pAcc->SetPixel( nY, nx, Color( (BYTE)( nRed - nMinMax ), (BYTE)( nGreen - nMinMax ), (BYTE)(nBlue - nMinMax) ) );
 			}
 		}
 		else if ( nPhotometricInterpretation == 5 && nSamplesPerPixel == 3 )
 		{
-			ULONG nMinMax =  nMinSampleValue * 255 / ( nMaxSampleValue - nMinSampleValue );
-			for ( nx = 0; nx < nImageWidth; nx++ )
+			if ( nMaxSampleValue > nMinSampleValue )
 			{
-				if ( nPlanes < 3 )
+				ULONG nMinMax =  nMinSampleValue * 255 / ( nMaxSampleValue - nMinSampleValue );
+				for ( nx = 0; nx < nImageWidth; nx++ )
 				{
-					nRed = GetBits( pMap[ 0 ],( nx * nSamplesPerPixel + 0 ) * nBitsPerSample, nBitsPerSample );
-					nGreen = GetBits( pMap[ 0 ],( nx * nSamplesPerPixel + 1 ) * nBitsPerSample, nBitsPerSample );
-					nBlue = GetBits( pMap[ 0 ],( nx * nSamplesPerPixel + 2 ) * nBitsPerSample, nBitsPerSample );
+					if ( nPlanes < 3 )
+					{
+						nRed = GetBits( pMap[ 0 ],( nx * nSamplesPerPixel + 0 ) * nBitsPerSample, nBitsPerSample );
+						nGreen = GetBits( pMap[ 0 ],( nx * nSamplesPerPixel + 1 ) * nBitsPerSample, nBitsPerSample );
+						nBlue = GetBits( pMap[ 0 ],( nx * nSamplesPerPixel + 2 ) * nBitsPerSample, nBitsPerSample );
+					}
+					else
+					{
+						nRed = GetBits( pMap[ 0 ], nx * nBitsPerSample, nBitsPerSample );
+						nGreen = GetBits( pMap[ 1 ], nx * nBitsPerSample, nBitsPerSample );
+						nBlue = GetBits( pMap[ 2 ], nx * nBitsPerSample, nBitsPerSample );
+					}
+					nRed = 255 - (BYTE)( nRed - nMinMax );
+					nGreen = 255 - (BYTE)( nGreen - nMinMax );
+					nBlue = 255 - (BYTE)( nBlue - nMinMax );
+					pAcc->SetPixel( nY, nx, Color( (BYTE) nRed, (BYTE) nGreen, (BYTE) nBlue ) );
 				}
-				else
-				{
-					nRed = GetBits( pMap[ 0 ], nx * nBitsPerSample, nBitsPerSample );
-					nGreen = GetBits( pMap[ 1 ], nx * nBitsPerSample, nBitsPerSample );
-					nBlue = GetBits( pMap[ 2 ], nx * nBitsPerSample, nBitsPerSample );
-				}
-				nRed = 255 - (BYTE)( nRed - nMinMax );
-				nGreen = 255 - (BYTE)( nGreen - nMinMax );
-				nBlue = 255 - (BYTE)( nBlue - nMinMax );
-				pAcc->SetPixel( nY, nx, Color( (BYTE) nRed, (BYTE) nGreen, (BYTE) nBlue ) );
 			}
 		}
 		else if( nPhotometricInterpretation == 5 && nSamplesPerPixel == 4 )
 		{
-			BYTE	nSamp[ 4 ];
-			BYTE	nSampLast[ 4 ] = { 0, 0, 0, 0 };
-			long	nBlack;
+			if ( nMaxSampleValue > nMinSampleValue )
+			{
+				BYTE	nSamp[ 4 ];
+				BYTE	nSampLast[ 4 ] = { 0, 0, 0, 0 };
+				long	nBlack;
 
-			for( nx = 0; nx < nImageWidth; nx++ )
-			{
-				// sind die Werte als Differenz abgelegt?
-				if( 2 == nPredictor )
+				for( nx = 0; nx < nImageWidth; nx++ )
 				{
-					for( ns = 0; ns < 4; ns++ )
+					// sind die Werte als Differenz abgelegt?
+					if( 2 == nPredictor )
 					{
-						if( nPlanes < 3 )
-							nSampLast[ ns ] = nSampLast[ ns ] + (BYTE) GetBits( pMap[ 0 ], ( nx * nSamplesPerPixel + ns ) * nBitsPerSample, nBitsPerSample );
-						else
-                            nSampLast[ ns ] = nSampLast[ ns ] + (BYTE) GetBits( pMap[ ns ], nx * nBitsPerSample, nBitsPerSample );
-                        nSamp[ ns ] = nSampLast[ ns ];
+						for( ns = 0; ns < 4; ns++ )
+						{
+							if( nPlanes < 3 )
+								nSampLast[ ns ] = nSampLast[ ns ] + (BYTE) GetBits( pMap[ 0 ], ( nx * nSamplesPerPixel + ns ) * nBitsPerSample, nBitsPerSample );
+							else
+								nSampLast[ ns ] = nSampLast[ ns ] + (BYTE) GetBits( pMap[ ns ], nx * nBitsPerSample, nBitsPerSample );
+							nSamp[ ns ] = nSampLast[ ns ];
+						}
 					}
+					else
+					{
+						for( ns = 0; ns < 4; ns++ )
+						{
+							if( nPlanes < 3 )
+								nSamp[ ns ] = (BYTE) GetBits( pMap[ 0 ], ( nx * nSamplesPerPixel + ns ) * nBitsPerSample, nBitsPerSample );
+							else
+								nSamp[ ns ]= (BYTE) GetBits( pMap[ ns ], nx * nBitsPerSample, nBitsPerSample );
+						}
+					}
+					nBlack = nSamp[ 3 ];
+					nRed = (BYTE) Max( 0L, 255L - ( ( (long) nSamp[ 0 ] + nBlack - ( ( (long) nMinSampleValue ) << 1 ) ) *
+								255L/(long)(nMaxSampleValue-nMinSampleValue) ) );
+					nGreen = (BYTE) Max( 0L, 255L - ( ( (long) nSamp[ 1 ] + nBlack - ( ( (long) nMinSampleValue ) << 1 ) ) *
+								255L/(long)(nMaxSampleValue-nMinSampleValue) ) );
+					nBlue = (BYTE) Max( 0L, 255L - ( ( (long) nSamp[ 2 ] + nBlack - ( ( (long) nMinSampleValue ) << 1 ) ) *
+								255L/(long)(nMaxSampleValue-nMinSampleValue) ) );
+					pAcc->SetPixel( nY, nx, Color ( (BYTE)nRed, (BYTE)nGreen, (BYTE)nBlue ) );
 				}
-				else
-				{
-					for( ns = 0; ns < 4; ns++ )
-					{
-						if( nPlanes < 3 )
-							nSamp[ ns ] = (BYTE) GetBits( pMap[ 0 ], ( nx * nSamplesPerPixel + ns ) * nBitsPerSample, nBitsPerSample );
-						else
-							nSamp[ ns ]= (BYTE) GetBits( pMap[ ns ], nx * nBitsPerSample, nBitsPerSample );
-					}
-				}
-				nBlack = nSamp[ 3 ];
-				nRed = (BYTE) Max( 0L, 255L - ( ( (long) nSamp[ 0 ] + nBlack - ( ( (long) nMinSampleValue ) << 1 ) ) *
-							255L/(long)(nMaxSampleValue-nMinSampleValue) ) );
-				nGreen = (BYTE) Max( 0L, 255L - ( ( (long) nSamp[ 1 ] + nBlack - ( ( (long) nMinSampleValue ) << 1 ) ) *
-							255L/(long)(nMaxSampleValue-nMinSampleValue) ) );
-				nBlue = (BYTE) Max( 0L, 255L - ( ( (long) nSamp[ 2 ] + nBlack - ( ( (long) nMinSampleValue ) << 1 ) ) *
-							255L/(long)(nMaxSampleValue-nMinSampleValue) ) );
-				pAcc->SetPixel( nY, nx, Color ( (BYTE)nRed, (BYTE)nGreen, (BYTE)nBlue ) );
-
 			}
 		}
 	}
 	else if ( nSamplesPerPixel == 1 && ( nPhotometricInterpretation <= 1 || nPhotometricInterpretation == 3 ) )
 	{
-		ULONG nMinMax = ( ( 1 << nDstBitsPerPixel ) - 1 ) / ( nMaxSampleValue - nMinSampleValue );
-		BYTE* pt = pMap[ 0 ];
-		BYTE nShift;
+		if ( nMaxSampleValue > nMinSampleValue )
+		{
+			ULONG nMinMax = ( ( 1 << nDstBitsPerPixel ) - 1 ) / ( nMaxSampleValue - nMinSampleValue );
+			BYTE* pt = pMap[ 0 ];
+			BYTE nShift;
 
-		switch ( nDstBitsPerPixel )
-		{
-			case 8 :
+			switch ( nDstBitsPerPixel )
 			{
-				BYTE nLast;
-				if ( bByteSwap )
+				case 8 :
 				{
-					if ( nPredictor == 2 )
+					BYTE nLast;
+					if ( bByteSwap )
 					{
-						nLast = BYTESWAP( (BYTE)*pt++ );
-						for ( nx = 0; nx < nImageWidth; nx++ )
+						if ( nPredictor == 2 )
 						{
-							pAcc->SetPixel( nY, nx, nLast );
-							nLast = nLast + *pt++;
+							nLast = BYTESWAP( (BYTE)*pt++ );
+							for ( nx = 0; nx < nImageWidth; nx++ )
+							{
+								pAcc->SetPixel( nY, nx, nLast );
+								nLast = nLast + *pt++;
+							}
+						}
+						else
+						{
+							for ( nx = 0; nx < nImageWidth; nx++ )
+							{
+								nLast = *pt++;
+								pAcc->SetPixel( nY, nx, (BYTE)( ( (BYTESWAP((ULONG)nLast ) - nMinSampleValue ) * nMinMax ) ) );
+							}
 						}
 					}
 					else
 					{
-						for ( nx = 0; nx < nImageWidth; nx++ )
+						if ( nPredictor == 2 )
 						{
 							nLast = *pt++;
-							pAcc->SetPixel( nY, nx, (BYTE)( ( (BYTESWAP((ULONG)nLast ) - nMinSampleValue ) * nMinMax ) ) );
+							for ( nx = 0; nx < nImageWidth; nx++ )
+							{
+								pAcc->SetPixel( nY, nx, nLast );
+								nLast = nLast + *pt++;
+							}
+						}
+						else
+						{
+							for ( nx = 0; nx < nImageWidth; nx++ )
+							{
+								pAcc->SetPixel( nY, nx, (BYTE)( ( (ULONG)*pt++ - nMinSampleValue ) * nMinMax ) );
+
+							}
 						}
 					}
 				}
-				else
+				break;
+
+				case 7 :
+				case 6 :
+				case 5 :
+				case 4 :
+				case 3 :
+				case 2 :
 				{
-					if ( nPredictor == 2 )
+					for ( nx = 0; nx < nImageWidth; nx++ )
 					{
-						nLast = *pt++;
-						for ( nx = 0; nx < nImageWidth; nx++ )
+						nVal = ( GetBits( pt, nx * nBitsPerSample, nBitsPerSample ) - nMinSampleValue ) * nMinMax;
+						pAcc->SetPixel( nY, nx, (BYTE)nVal );
+					}
+				}
+				break;
+
+				case 1 :
+				{
+					if ( bByteSwap )
+					{
+						nx = 0;
+						nByteCount = ( nImageWidth >> 3 ) + 1;
+						while ( --nByteCount )
 						{
-							pAcc->SetPixel( nY, nx, nLast );
-							nLast = nLast + *pt++;
+							nByteVal = *pt++;
+							pAcc->SetPixel( nY, nx++, nByteVal & 1 );
+							nByteVal >>= 1;
+							pAcc->SetPixel( nY, nx++, nByteVal & 1 );
+							nByteVal >>= 1;
+							pAcc->SetPixel( nY, nx++, nByteVal & 1 );
+							nByteVal >>= 1;
+							pAcc->SetPixel( nY, nx++, nByteVal & 1 );
+							nByteVal >>= 1;
+							pAcc->SetPixel( nY, nx++, nByteVal & 1 );
+							nByteVal >>= 1;
+							pAcc->SetPixel( nY, nx++, nByteVal & 1 );
+							nByteVal >>= 1;
+							pAcc->SetPixel( nY, nx++, nByteVal & 1 );
+							nByteVal >>= 1;
+							pAcc->SetPixel( nY, nx++, nByteVal );
+						}
+						if ( nImageWidth & 7 )
+						{
+							nByteVal = *pt++;
+							while ( nx < nImageWidth )
+							{
+								pAcc->SetPixel( nY, nx++, nByteVal & 1 );
+								nByteVal >>= 1;
+							}
 						}
 					}
 					else
 					{
-						for ( nx = 0; nx < nImageWidth; nx++ )
+						nx = 7;
+						nByteCount = ( nImageWidth >> 3 ) + 1;
+						while ( --nByteCount )
 						{
-							pAcc->SetPixel( nY, nx, (BYTE)( ( (ULONG)*pt++ - nMinSampleValue ) * nMinMax ) );
-
+							nByteVal = *pt++;
+							pAcc->SetPixel( nY, nx, nByteVal & 1 );
+							nByteVal >>= 1;
+							pAcc->SetPixel( nY, --nx, nByteVal & 1 );
+							nByteVal >>= 1;
+							pAcc->SetPixel( nY, --nx, nByteVal & 1 );
+							nByteVal >>= 1;
+							pAcc->SetPixel( nY, --nx, nByteVal & 1 );
+							nByteVal >>= 1;
+							pAcc->SetPixel( nY, --nx, nByteVal & 1 );
+							nByteVal >>= 1;
+							pAcc->SetPixel( nY, --nx, nByteVal & 1 );
+							nByteVal >>= 1;
+							pAcc->SetPixel( nY, --nx, nByteVal & 1 );
+							nByteVal >>= 1;
+							pAcc->SetPixel( nY, --nx, nByteVal );
+							nx += 15;
+						}
+						if ( nImageWidth & 7 )
+						{
+							nx -= 7;
+							nByteVal = *pt++;
+							nShift = 7;
+							while ( nx < nImageWidth )
+							{
+								pAcc->SetPixel( nY, nx++, ( nByteVal >> nShift ) & 1);
+							}
 						}
 					}
 				}
+				break;
+
+				default :
+					return FALSE;
 			}
-			break;
-
-			case 7 :
-			case 6 :
-			case 5 :
-			case 4 :
-			case 3 :
-			case 2 :
-			{
-				for ( nx = 0; nx < nImageWidth; nx++ )
-				{
-					nVal = ( GetBits( pt, nx * nBitsPerSample, nBitsPerSample ) - nMinSampleValue ) * nMinMax;
-					pAcc->SetPixel( nY, nx, (BYTE)nVal );
-				}
-			}
-			break;
-
-			case 1 :
-			{
-				if ( bByteSwap )
-				{
-					nx = 0;
-					nByteCount = ( nImageWidth >> 3 ) + 1;
-					while ( --nByteCount )
-					{
-						nByteVal = *pt++;
-						pAcc->SetPixel( nY, nx++, nByteVal & 1 );
-						nByteVal >>= 1;
-						pAcc->SetPixel( nY, nx++, nByteVal & 1 );
-						nByteVal >>= 1;
-						pAcc->SetPixel( nY, nx++, nByteVal & 1 );
-						nByteVal >>= 1;
-						pAcc->SetPixel( nY, nx++, nByteVal & 1 );
-						nByteVal >>= 1;
-						pAcc->SetPixel( nY, nx++, nByteVal & 1 );
-						nByteVal >>= 1;
-						pAcc->SetPixel( nY, nx++, nByteVal & 1 );
-						nByteVal >>= 1;
-						pAcc->SetPixel( nY, nx++, nByteVal & 1 );
-						nByteVal >>= 1;
-						pAcc->SetPixel( nY, nx++, nByteVal );
-					}
-					if ( nImageWidth & 7 )
-					{
-						nByteVal = *pt++;
-						while ( nx < nImageWidth )
-						{
-							pAcc->SetPixel( nY, nx++, nByteVal & 1 );
-							nByteVal >>= 1;
-						}
-					}
-				}
-				else
-				{
-					nx = 7;
-					nByteCount = ( nImageWidth >> 3 ) + 1;
-					while ( --nByteCount )
-					{
-						nByteVal = *pt++;
-						pAcc->SetPixel( nY, nx, nByteVal & 1 );
-						nByteVal >>= 1;
-						pAcc->SetPixel( nY, --nx, nByteVal & 1 );
-						nByteVal >>= 1;
-						pAcc->SetPixel( nY, --nx, nByteVal & 1 );
-						nByteVal >>= 1;
-						pAcc->SetPixel( nY, --nx, nByteVal & 1 );
-						nByteVal >>= 1;
-						pAcc->SetPixel( nY, --nx, nByteVal & 1 );
-						nByteVal >>= 1;
-						pAcc->SetPixel( nY, --nx, nByteVal & 1 );
-						nByteVal >>= 1;
-						pAcc->SetPixel( nY, --nx, nByteVal & 1 );
-						nByteVal >>= 1;
-						pAcc->SetPixel( nY, --nx, nByteVal );
-						nx += 15;
-					}
-					if ( nImageWidth & 7 )
-					{
-						nx -= 7;
-						nByteVal = *pt++;
-						nShift = 7;
-						while ( nx < nImageWidth )
-						{
-							pAcc->SetPixel( nY, nx++, ( nByteVal >> nShift ) & 1);
-						}
-					}
-				}
-			}
-			break;
-
-			default :
-				return FALSE;
 		}
 	}
 	else if ( ( nSamplesPerPixel == 2 ) && ( nBitsPerSample == 8 ) &&
 		( nPlanarConfiguration == 1 ) && ( pColorMap == 0 ) )				// grayscale
 	{
-		ULONG nMinMax = ( ( 1 << 8 /*nDstBitsPerPixel*/ ) - 1 ) / ( nMaxSampleValue - nMinSampleValue );
-		BYTE*	pt = pMap[ 0 ];
-		if ( nByte1 == 'I' )
-			pt++;
-		for ( nx = 0; nx < nImageWidth; nx++, pt += 2 )
+		if ( nMaxSampleValue > nMinSampleValue )
 		{
-			pAcc->SetPixel( nY, nx, (BYTE)( ( (ULONG)*pt - nMinSampleValue ) * nMinMax ) );
+			ULONG nMinMax = ( ( 1 << 8 /*nDstBitsPerPixel*/ ) - 1 ) / ( nMaxSampleValue - nMinSampleValue );
+			BYTE*	pt = pMap[ 0 ];
+			if ( nByte1 == 'I' )
+				pt++;
+			for ( nx = 0; nx < nImageWidth; nx++, pt += 2 )
+			{
+				pAcc->SetPixel( nY, nx, (BYTE)( ( (ULONG)*pt - nMinSampleValue ) * nMinMax ) );
+			}
 		}
 	}
 	else
 				if ( pTIFF->IsEof() )
 					nNextIfd = 0;
 			}
+			if ( !nBitsPerSample || ( nBitsPerSample > 32 ) )
+				bStatus = FALSE;
 			if ( bStatus )
 			{
 				if ( nMaxSampleValue == 0 )
-					nMaxSampleValue = ( 1 << nBitsPerSample ) - 1;
-
+				{
+					if ( nBitsPerSample == 32 )			// sj: i93300, compiler bug, 1 << 32 gives 1 one 32bit windows platforms,
+						nMaxSampleValue = 0xffffffff;	// (up from 80286 only the lower 5 bits are used when shifting a 32bit register)
+					else
+						nMaxSampleValue = ( 1 << nBitsPerSample ) - 1;
+				}
 				if ( nPhotometricInterpretation == 2 || nPhotometricInterpretation == 5 || nPhotometricInterpretation == 6 )
 					nDstBitsPerPixel = 24;
 				else if ( nBitsPerSample*nSamplesPerPixel <= 1 )

filter/source/msfilter/mscodec.cxx

 #include <string.h>
 #include <tools/solar.h>
 
+#include <comphelper/sequenceashashmap.hxx>
+#include <comphelper/docpasswordhelper.hxx>
+
 #define DEBUG_MSO_ENCRYPTION_STD97 0
 
 #if DEBUG_MSO_ENCRYPTION_STD97
 #include <stdio.h>
 #endif
 
+using namespace ::com::sun::star;
 
 namespace msfilter {
 
     }
 }
 
+sal_Bool MSCodec_Xor95::InitCodec( const uno::Sequence< beans::NamedValue >& aData )
+{
+    sal_Bool bResult = sal_False;
+
+	::comphelper::SequenceAsHashMap aHashData( aData );
+    uno::Sequence< sal_Int8 > aKey = aHashData.getUnpackedValueOrDefault( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "XOR95EncryptionKey" ) ), uno::Sequence< sal_Int8 >() );
+
+    if ( aKey.getLength() == 16 )
+    {
+        (void)memcpy( mpnKey, aKey.getConstArray(), 16 );
+        bResult = sal_True;
+
+        mnKey = (sal_uInt16)aHashData.getUnpackedValueOrDefault( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "XOR95BaseKey" ) ), (sal_Int16)0 );
+        mnHash = (sal_uInt16)aHashData.getUnpackedValueOrDefault( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "XOR95PasswordHash" ) ), (sal_Int16)0 );
+    }
+    else
+        OSL_ENSURE( sal_False, "Unexpected key size!\n" );
+
+    return bResult;
+}
+
+uno::Sequence< beans::NamedValue > MSCodec_Xor95::GetEncryptionData()
+{
+    ::comphelper::SequenceAsHashMap aHashData;
+    aHashData[ ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "XOR95EncryptionKey" ) ) ] <<= uno::Sequence<sal_Int8>( (sal_Int8*)mpnKey, 16 );
+    aHashData[ ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "XOR95BaseKey" ) ) ] <<= (sal_Int16)mnKey;
+    aHashData[ ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "XOR95PasswordHash" ) ) ] <<= (sal_Int16)mnHash;
+
+    return aHashData.getAsConstNamedValueList();
+}
+
 bool MSCodec_Xor95::VerifyKey( sal_uInt16 nKey, sal_uInt16 nHash ) const
 {
     return (nKey == mnKey) && (nHash == mnHash);
     mnOffset = (mnOffset + nBytes) & 0x0F;
 }
 
-sal_uInt16 MSCodec_Xor95::GetHash( const sal_uInt8* pnPassData, sal_Size nSize )
-{
-    return lclGetHash( pnPassData, nSize );
-}
-
 // ============================================================================
 
 MSCodec_Std97::MSCodec_Std97 ()
     OSL_ASSERT(m_hDigest != 0);
 
     (void)memset (m_pDigestValue, 0, sizeof(m_pDigestValue));
+    (void)memset (m_pDocId, 0, sizeof(m_pDocId));
 }
 
 MSCodec_Std97::~MSCodec_Std97 ()
 {
     (void)memset (m_pDigestValue, 0, sizeof(m_pDigestValue));
+    (void)memset (m_pDocId, 0, sizeof(m_pDocId));
     rtl_digest_destroy (m_hDigest);
     rtl_cipher_destroy (m_hCipher);
 }
 
+#if 0
 #if DEBUG_MSO_ENCRYPTION_STD97    
 static void lcl_P