bug: bug on save onlyoffice extention for comments in xlsx

This commit is contained in:
Sergey Konovalov
2018-01-29 19:51:06 +03:00
parent f124d18256
commit 3d1db63c0e
2 changed files with 20 additions and 8 deletions

View File

@ -3368,19 +3368,31 @@ namespace BinXlsxRW
if(oComment.m_sGfxdata.IsInit())
{
const std::wstring& sGfxData = oComment.m_sGfxdata.get2();
std::wstring sSignatureBase64(_T("WExTV"));
if(sSignatureBase64 == sGfxData.substr(0, sSignatureBase64.length()))
std::wstring sSignatureBase64Old(_T("WExTV"));//XLST
std::wstring sSignatureBase64(_T("WExTM"));//XLS2
//compatibility with fact that previously used long that can be 4 or 8 byte
bool bCompatibility = sSignatureBase64Old == sGfxData.substr(0, sSignatureBase64Old.length());
bool isComment = (sSignatureBase64 == sGfxData.substr(0, sSignatureBase64.length())) || bCompatibility;
if(isComment)
{
std::string sSignature("XLST");
std::string sSignature("XLS2");
int nSignatureSize = (int)sSignature.length();
int nDataLengthSize = sizeof(long);
int nDataLengthSize = bCompatibility ? sizeof(long) : sizeof(_INT32);
int nJunkSize = 2;
std::string sGfxDataA = std::string(sGfxData.begin(), sGfxData.end());
int nDataSize = (int)sGfxDataA.length();
BYTE* pBuffer = new BYTE[nDataSize];
if(false != Base64::Base64Decode((const char*)sGfxDataA.c_str(), (int)sGfxDataA.length(), pBuffer, &nDataSize))
{
int nLength = *((long*)(pBuffer + nSignatureSize));
int nLength;
if (bCompatibility)
{
nLength = *((long*)(pBuffer + nSignatureSize));
}
else
{
nLength = *((_INT32*)(pBuffer + nSignatureSize));
}
NSBinPptxRW::CBinaryFileReader oBufferedStream;
oBufferedStream.Init((BYTE*)pBuffer, nSignatureSize + nDataLengthSize, nLength);

View File

@ -2236,16 +2236,16 @@ namespace BinXlsxRW
BYTE* pSourceBuffer = m_oBufferedStream.GetPointer(length);
m_oBufferedStream.Seek(nStartPos);
std::string sSignature("XLST");
std::string sSignature("XLS2");
int nSignatureSize = (int)sSignature.length();
int nDataLengthSize = sizeof(long);
int nDataLengthSize = sizeof(_INT32);
int nJunkSize = 2;
int nWriteBufferLength = nSignatureSize + nDataLengthSize + length + nJunkSize;
BYTE* pWriteBuffer = new BYTE[nWriteBufferLength];
memcpy(pWriteBuffer, sSignature.c_str(), nSignatureSize);
memcpy(pWriteBuffer + nSignatureSize, &length, nDataLengthSize);
*((_INT32*)(pWriteBuffer + nSignatureSize)) = (_INT32)length;
memcpy(pWriteBuffer + nSignatureSize + nDataLengthSize, pSourceBuffer, length);
//пишем в конце 0, потому что при редактировании Excel меняет посление байты.
memset(pWriteBuffer + nSignatureSize + nDataLengthSize + length, 0, nJunkSize);