diff --git a/OfficeCryptReader/source/CryptTransform.cpp b/OfficeCryptReader/source/CryptTransform.cpp index a03c1446b0..6a13000cb4 100644 --- a/OfficeCryptReader/source/CryptTransform.cpp +++ b/OfficeCryptReader/source/CryptTransform.cpp @@ -1140,6 +1140,8 @@ int ECMAEncryptor::Encrypt(unsigned char* data_inp_ptr, int size, unsigned char* unsigned char* data_inp = data_inp_ptr; unsigned char* data_out = data_out_ptr + 8; + int result_size_out = 0; + if (cryptData.bAgile) { _buf pBlockKey ((unsigned char*)encrKeyValueBlockKey, 8); @@ -1204,7 +1206,7 @@ int ECMAEncryptor::Encrypt(unsigned char* data_inp_ptr, int size, unsigned char* enc_size += sz; i++; } - return enc_size + 8; + result_size_out = enc_size + 8; } else { @@ -1221,8 +1223,9 @@ int ECMAEncryptor::Encrypt(unsigned char* data_inp_ptr, int size, unsigned char* EncryptCipher(hashKey, empty, pInp, pOut, cryptData.cipherAlgorithm/*, StreamTransformationFilter::ZEROS_PADDING*/); - return size_out + 8; + result_size_out = size_out + 8; } + return result_size_out; } //----------------------------------------------------------------------------------------------------------- ODFDecryptor::ODFDecryptor() diff --git a/OfficeCryptReader/source/ECMACryptFile.cpp b/OfficeCryptReader/source/ECMACryptFile.cpp index 89e2301f8f..7603d55839 100644 --- a/OfficeCryptReader/source/ECMACryptFile.cpp +++ b/OfficeCryptReader/source/ECMACryptFile.cpp @@ -725,7 +725,7 @@ bool ECMACryptFile::EncryptOfficeFile(const std::wstring &file_name_inp, const s _UINT64 lengthFileSize = file.GetFileSize(); DWORD lengthData = lengthFileSize, lengthDataRead = 0 ; - unsigned char* data = new unsigned char[lengthData]; + unsigned char* data = new unsigned char[lengthData]; unsigned char* data_out = NULL; file.ReadFile(data, lengthData, lengthDataRead); @@ -734,9 +734,10 @@ bool ECMACryptFile::EncryptOfficeFile(const std::wstring &file_name_inp, const s lengthData = cryptor.Encrypt(data, lengthData, data_out); + delete[]data; data = NULL; + if (NULL == data_out) { - delete []data; return false; } cryptor.UpdateDataIntegrity(data_out, lengthData); @@ -910,7 +911,7 @@ bool ECMACryptFile::EncryptOfficeFile(const std::wstring &file_name_inp, const s // // if (decryptor.SetPassword(password)) // { -// unsigned char* data_out2 = NULL; +// unsigned char* data_out2 = NULL; // decryptor.Decrypt(data_out, lengthData, data_out2, 0); // // bool bDataIntegrity = decryptor.CheckDataIntegrity(data_out, lengthData); @@ -1029,7 +1030,7 @@ bool ECMACryptFile::DecryptOfficeFile(const std::wstring &file_name_inp, const s { _UINT64 lengthData, lengthRead = pStream->size(); - unsigned char* data = new unsigned char[lengthRead]; + unsigned char* data = new unsigned char[lengthRead]; unsigned char* data_out = NULL; int readTrue = pStream->read(data, lengthRead);