Fix bug 70042

This commit is contained in:
Svetlana Kulikova
2024-09-23 19:08:27 +03:00
parent 30868b81bc
commit f0f4e39f5c
2 changed files with 53 additions and 4 deletions

View File

@ -238,11 +238,24 @@ bool COfficeFileFormatChecker::isPdfFormatFile(unsigned char *pBuffer, int dwByt
if (NULL == pFirst) if (NULL == pFirst)
{ {
//skip special char* pData = (char*)pBuffer;
_UINT16 sz = pBuffer[0] + (pBuffer[1] << 8); for (int i = 0; i < dwBytes - 5; ++i)
if (sz < dwBytes - 8)
{ {
pFirst = strstr((char*)(pBuffer + sz), "%PDF-"); int nPDF = strncmp(&pData[i], "%PDF-", 5);
if (!nPDF)
{
pFirst = (char*)pBuffer + i;
break;
}
}
if (NULL == pFirst)
{
//skip special
_UINT16 sz = pBuffer[0] + (pBuffer[1] << 8);
if (sz < dwBytes - 8)
{
pFirst = strstr((char*)(pBuffer + sz), "%PDF-");
}
} }
} }
if (NULL != pFirst) if (NULL != pFirst)

View File

@ -196,6 +196,42 @@ TEST_F(CPdfFileTest, GetMetaData)
RELEASEARRAYOBJECTS(pMetaData); RELEASEARRAYOBJECTS(pMetaData);
} }
TEST_F(CPdfFileTest, PdfType)
{
//GTEST_SKIP();
NSFile::CFileBinary oFile;
ASSERT_TRUE(oFile.OpenFile(wsSrcFile));
int nSize = 4096;
BYTE* pBuffer = new BYTE[nSize];
if (!pBuffer)
{
oFile.CloseFile();
return;
}
DWORD dwReadBytes = 0;
oFile.ReadFile(pBuffer, nSize, dwReadBytes);
oFile.CloseFile();
char* pData = (char*)pBuffer;
bool bPDF = false;
for (int i = 0; i < nSize - 5; ++i)
{
int nPDF = strncmp(&pData[i], "%PDF-", 5);
if (!nPDF)
{
bPDF = true;
break;
}
}
ASSERT_TRUE(bPDF);
RELEASEARRAYOBJECTS(pBuffer);
}
TEST_F(CPdfFileTest, ValidMetaData) TEST_F(CPdfFileTest, ValidMetaData)
{ {
GTEST_SKIP(); GTEST_SKIP();