| OLD | NEW |
| 1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
| 6 | 6 |
| 7 #include <set> | 7 #include <set> |
| 8 #include <utility> | 8 #include <utility> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 if (pType->GetString() == FX_BSTRC("Sig")) { | 89 if (pType->GetString() == FX_BSTRC("Sig")) { |
| 90 return TRUE; | 90 return TRUE; |
| 91 } | 91 } |
| 92 return FALSE; | 92 return FALSE; |
| 93 } | 93 } |
| 94 | 94 |
| 95 CPDF_Parser::CPDF_Parser() { | 95 CPDF_Parser::CPDF_Parser() { |
| 96 m_pDocument = NULL; | 96 m_pDocument = NULL; |
| 97 m_pTrailer = NULL; | 97 m_pTrailer = NULL; |
| 98 m_pEncryptDict = NULL; | 98 m_pEncryptDict = NULL; |
| 99 m_pSecurityHandler = NULL; | |
| 100 m_pLinearized = NULL; | 99 m_pLinearized = NULL; |
| 101 m_dwFirstPageNo = 0; | 100 m_dwFirstPageNo = 0; |
| 102 m_dwXrefStartObjNum = 0; | 101 m_dwXrefStartObjNum = 0; |
| 103 m_bOwnFileRead = TRUE; | 102 m_bOwnFileRead = TRUE; |
| 104 m_FileVersion = 0; | 103 m_FileVersion = 0; |
| 105 m_bForceUseSecurityHandler = FALSE; | 104 m_bForceUseSecurityHandler = FALSE; |
| 106 } | 105 } |
| 107 CPDF_Parser::~CPDF_Parser() { | 106 CPDF_Parser::~CPDF_Parser() { |
| 108 CloseParser(FALSE); | 107 CloseParser(FALSE); |
| 109 } | 108 } |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 280 } else if (pEncryptObj->GetType() == PDFOBJ_REFERENCE) { | 279 } else if (pEncryptObj->GetType() == PDFOBJ_REFERENCE) { |
| 281 pEncryptObj = m_pDocument->GetIndirectObject( | 280 pEncryptObj = m_pDocument->GetIndirectObject( |
| 282 ((CPDF_Reference*)pEncryptObj)->GetRefObjNum()); | 281 ((CPDF_Reference*)pEncryptObj)->GetRefObjNum()); |
| 283 if (pEncryptObj) { | 282 if (pEncryptObj) { |
| 284 SetEncryptDictionary(pEncryptObj->GetDict()); | 283 SetEncryptDictionary(pEncryptObj->GetDict()); |
| 285 } | 284 } |
| 286 } | 285 } |
| 287 } | 286 } |
| 288 if (m_bForceUseSecurityHandler) { | 287 if (m_bForceUseSecurityHandler) { |
| 289 FX_DWORD err = PDFPARSE_ERROR_HANDLER; | 288 FX_DWORD err = PDFPARSE_ERROR_HANDLER; |
| 290 if (m_pSecurityHandler == NULL) { | 289 if (!m_pSecurityHandler) { |
| 291 return PDFPARSE_ERROR_HANDLER; | 290 return PDFPARSE_ERROR_HANDLER; |
| 292 } | 291 } |
| 293 if (!m_pSecurityHandler->OnInit(this, m_pEncryptDict)) { | 292 if (!m_pSecurityHandler->OnInit(this, m_pEncryptDict)) { |
| 294 return err; | 293 return err; |
| 295 } | 294 } |
| 296 CPDF_CryptoHandler* pCryptoHandler = | 295 nonstd::unique_ptr<CPDF_CryptoHandler> pCryptoHandler( |
| 297 m_pSecurityHandler->CreateCryptoHandler(); | 296 m_pSecurityHandler->CreateCryptoHandler()); |
| 298 if (!pCryptoHandler->Init(m_pEncryptDict, m_pSecurityHandler)) { | 297 if (!pCryptoHandler->Init(m_pEncryptDict, m_pSecurityHandler.get())) { |
| 299 delete pCryptoHandler; | |
| 300 pCryptoHandler = NULL; | |
| 301 return PDFPARSE_ERROR_HANDLER; | 298 return PDFPARSE_ERROR_HANDLER; |
| 302 } | 299 } |
| 303 m_Syntax.SetEncrypt(pCryptoHandler); | 300 m_Syntax.SetEncrypt(pCryptoHandler.release()); |
| 304 } else if (m_pEncryptDict) { | 301 } else if (m_pEncryptDict) { |
| 305 CFX_ByteString filter = m_pEncryptDict->GetString(FX_BSTRC("Filter")); | 302 CFX_ByteString filter = m_pEncryptDict->GetString(FX_BSTRC("Filter")); |
| 306 CPDF_SecurityHandler* pSecurityHandler = NULL; | 303 nonstd::unique_ptr<CPDF_SecurityHandler> pSecurityHandler; |
| 307 FX_DWORD err = PDFPARSE_ERROR_HANDLER; | 304 FX_DWORD err = PDFPARSE_ERROR_HANDLER; |
| 308 if (filter == FX_BSTRC("Standard")) { | 305 if (filter == FX_BSTRC("Standard")) { |
| 309 pSecurityHandler = FPDF_CreateStandardSecurityHandler(); | 306 pSecurityHandler.reset(FPDF_CreateStandardSecurityHandler()); |
| 310 err = PDFPARSE_ERROR_PASSWORD; | 307 err = PDFPARSE_ERROR_PASSWORD; |
| 311 } | 308 } |
| 312 if (pSecurityHandler == NULL) { | 309 if (!pSecurityHandler) { |
| 313 return PDFPARSE_ERROR_HANDLER; | 310 return PDFPARSE_ERROR_HANDLER; |
| 314 } | 311 } |
| 315 if (!pSecurityHandler->OnInit(this, m_pEncryptDict)) { | 312 if (!pSecurityHandler->OnInit(this, m_pEncryptDict)) { |
| 316 delete pSecurityHandler; | |
| 317 pSecurityHandler = NULL; | |
| 318 return err; | 313 return err; |
| 319 } | 314 } |
| 320 m_pSecurityHandler = pSecurityHandler; | 315 m_pSecurityHandler = nonstd::move(pSecurityHandler); |
| 321 CPDF_CryptoHandler* pCryptoHandler = | 316 nonstd::unique_ptr<CPDF_CryptoHandler> pCryptoHandler( |
| 322 pSecurityHandler->CreateCryptoHandler(); | 317 m_pSecurityHandler->CreateCryptoHandler()); |
| 323 if (!pCryptoHandler->Init(m_pEncryptDict, m_pSecurityHandler)) { | 318 if (!pCryptoHandler->Init(m_pEncryptDict, m_pSecurityHandler.get())) { |
| 324 delete pCryptoHandler; | |
| 325 pCryptoHandler = NULL; | |
| 326 return PDFPARSE_ERROR_HANDLER; | 319 return PDFPARSE_ERROR_HANDLER; |
| 327 } | 320 } |
| 328 m_Syntax.SetEncrypt(pCryptoHandler); | 321 m_Syntax.SetEncrypt(pCryptoHandler.release()); |
| 329 } | 322 } |
| 330 return PDFPARSE_ERROR_SUCCESS; | 323 return PDFPARSE_ERROR_SUCCESS; |
| 331 } | 324 } |
| 332 void CPDF_Parser::ReleaseEncryptHandler() { | 325 void CPDF_Parser::ReleaseEncryptHandler() { |
| 333 delete m_Syntax.m_pCryptoHandler; | 326 m_Syntax.m_pCryptoHandler.reset(); |
| 334 m_Syntax.m_pCryptoHandler = NULL; | |
| 335 if (!m_bForceUseSecurityHandler) { | 327 if (!m_bForceUseSecurityHandler) { |
| 336 delete m_pSecurityHandler; | 328 m_pSecurityHandler.reset(); |
| 337 m_pSecurityHandler = NULL; | |
| 338 } | 329 } |
| 339 } | 330 } |
| 340 FX_FILESIZE CPDF_Parser::GetObjectOffset(FX_DWORD objnum) { | 331 FX_FILESIZE CPDF_Parser::GetObjectOffset(FX_DWORD objnum) { |
| 341 if (objnum >= (FX_DWORD)m_CrossRef.GetSize()) { | 332 if (objnum >= (FX_DWORD)m_CrossRef.GetSize()) { |
| 342 return 0; | 333 return 0; |
| 343 } | 334 } |
| 344 if (m_V5Type[objnum] == 1) { | 335 if (m_V5Type[objnum] == 1) { |
| 345 return m_CrossRef[objnum]; | 336 return m_CrossRef[objnum]; |
| 346 } | 337 } |
| 347 if (m_V5Type[objnum] == 2) { | 338 if (m_V5Type[objnum] == 2) { |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 440 m_Syntax.RestorePos(dwStartPos); | 431 m_Syntax.RestorePos(dwStartPos); |
| 441 void* pResult = | 432 void* pResult = |
| 442 FXSYS_bsearch(&pos, m_SortedOffset.GetData(), m_SortedOffset.GetSize(), | 433 FXSYS_bsearch(&pos, m_SortedOffset.GetData(), m_SortedOffset.GetSize(), |
| 443 sizeof(FX_FILESIZE), CompareFileSize); | 434 sizeof(FX_FILESIZE), CompareFileSize); |
| 444 if (pResult == NULL) { | 435 if (pResult == NULL) { |
| 445 m_SortedOffset.Add(pos); | 436 m_SortedOffset.Add(pos); |
| 446 } | 437 } |
| 447 FX_DWORD start_objnum = 0; | 438 FX_DWORD start_objnum = 0; |
| 448 FX_DWORD count = dwObjCount; | 439 FX_DWORD count = dwObjCount; |
| 449 FX_FILESIZE SavedPos = m_Syntax.SavePos(); | 440 FX_FILESIZE SavedPos = m_Syntax.SavePos(); |
| 450 int32_t recordsize = 20; | 441 const int32_t recordsize = 20; |
| 451 char* pBuf = FX_Alloc(char, 1024 * recordsize + 1); | 442 std::vector<char> buf(1024 * recordsize + 1); |
| 452 pBuf[1024 * recordsize] = '\0'; | 443 buf[1024 * recordsize] = '\0'; |
| 453 int32_t nBlocks = count / 1024 + 1; | 444 int32_t nBlocks = count / 1024 + 1; |
| 454 for (int32_t block = 0; block < nBlocks; block++) { | 445 for (int32_t block = 0; block < nBlocks; block++) { |
| 455 int32_t block_size = block == nBlocks - 1 ? count % 1024 : 1024; | 446 int32_t block_size = block == nBlocks - 1 ? count % 1024 : 1024; |
| 456 FX_DWORD dwReadSize = block_size * recordsize; | 447 FX_DWORD dwReadSize = block_size * recordsize; |
| 457 if ((FX_FILESIZE)(dwStartPos + dwReadSize) > m_Syntax.m_FileLen) { | 448 if ((FX_FILESIZE)(dwStartPos + dwReadSize) > m_Syntax.m_FileLen) { |
| 458 FX_Free(pBuf); | |
| 459 return FALSE; | 449 return FALSE; |
| 460 } | 450 } |
| 461 if (!m_Syntax.ReadBlock((uint8_t*)pBuf, dwReadSize)) { | 451 if (!m_Syntax.ReadBlock((uint8_t*)buf.data(), dwReadSize)) { |
| 462 FX_Free(pBuf); | |
| 463 return FALSE; | 452 return FALSE; |
| 464 } | 453 } |
| 465 for (int32_t i = 0; i < block_size; i++) { | 454 for (int32_t i = 0; i < block_size; i++) { |
| 466 FX_DWORD objnum = start_objnum + block * 1024 + i; | 455 FX_DWORD objnum = start_objnum + block * 1024 + i; |
| 467 char* pEntry = pBuf + i * recordsize; | 456 char* pEntry = buf.data() + i * recordsize; |
| 468 if (pEntry[17] == 'f') { | 457 if (pEntry[17] == 'f') { |
| 469 m_CrossRef.SetAtGrow(objnum, 0); | 458 m_CrossRef.SetAtGrow(objnum, 0); |
| 470 m_V5Type.SetAtGrow(objnum, 0); | 459 m_V5Type.SetAtGrow(objnum, 0); |
| 471 } else { | 460 } else { |
| 472 int32_t offset = FXSYS_atoi(pEntry); | 461 int32_t offset = FXSYS_atoi(pEntry); |
| 473 if (offset == 0) { | 462 if (offset == 0) { |
| 474 for (int32_t c = 0; c < 10; c++) { | 463 for (int32_t c = 0; c < 10; c++) { |
| 475 if (pEntry[c] < '0' || pEntry[c] > '9') { | 464 if (pEntry[c] < '0' || pEntry[c] > '9') { |
| 476 FX_Free(pBuf); | |
| 477 return FALSE; | 465 return FALSE; |
| 478 } | 466 } |
| 479 } | 467 } |
| 480 } | 468 } |
| 481 m_CrossRef.SetAtGrow(objnum, offset); | 469 m_CrossRef.SetAtGrow(objnum, offset); |
| 482 int32_t version = FXSYS_atoi(pEntry + 11); | 470 int32_t version = FXSYS_atoi(pEntry + 11); |
| 483 if (version >= 1) { | 471 if (version >= 1) { |
| 484 m_bVersionUpdated = TRUE; | 472 m_bVersionUpdated = TRUE; |
| 485 } | 473 } |
| 486 m_ObjVersion.SetAtGrow(objnum, version); | 474 m_ObjVersion.SetAtGrow(objnum, version); |
| 487 if (m_CrossRef[objnum] < m_Syntax.m_FileLen) { | 475 if (m_CrossRef[objnum] < m_Syntax.m_FileLen) { |
| 488 void* pResult = FXSYS_bsearch( | 476 void* pResult = FXSYS_bsearch( |
| 489 &m_CrossRef[objnum], m_SortedOffset.GetData(), | 477 &m_CrossRef[objnum], m_SortedOffset.GetData(), |
| 490 m_SortedOffset.GetSize(), sizeof(FX_FILESIZE), CompareFileSize); | 478 m_SortedOffset.GetSize(), sizeof(FX_FILESIZE), CompareFileSize); |
| 491 if (pResult == NULL) { | 479 if (pResult == NULL) { |
| 492 m_SortedOffset.Add(m_CrossRef[objnum]); | 480 m_SortedOffset.Add(m_CrossRef[objnum]); |
| 493 } | 481 } |
| 494 } | 482 } |
| 495 m_V5Type.SetAtGrow(objnum, 1); | 483 m_V5Type.SetAtGrow(objnum, 1); |
| 496 } | 484 } |
| 497 } | 485 } |
| 498 } | 486 } |
| 499 FX_Free(pBuf); | |
| 500 m_Syntax.RestorePos(SavedPos + count * recordsize); | 487 m_Syntax.RestorePos(SavedPos + count * recordsize); |
| 501 return TRUE; | 488 return TRUE; |
| 502 } | 489 } |
| 503 | 490 |
| 504 bool CPDF_Parser::FindPosInOffsets(FX_FILESIZE pos) const { | 491 bool CPDF_Parser::FindPosInOffsets(FX_FILESIZE pos) const { |
| 505 return FXSYS_bsearch(&pos, m_SortedOffset.GetData(), m_SortedOffset.GetSize(), | 492 return FXSYS_bsearch(&pos, m_SortedOffset.GetData(), m_SortedOffset.GetSize(), |
| 506 sizeof(FX_FILESIZE), CompareFileSize); | 493 sizeof(FX_FILESIZE), CompareFileSize); |
| 507 } | 494 } |
| 508 | 495 |
| 509 bool CPDF_Parser::LoadCrossRefV4(FX_FILESIZE pos, | 496 bool CPDF_Parser::LoadCrossRefV4(FX_FILESIZE pos, |
| (...skipping 22 matching lines...) Expand all Loading... |
| 532 break; | 519 break; |
| 533 } | 520 } |
| 534 FX_DWORD start_objnum = FXSYS_atoi(word); | 521 FX_DWORD start_objnum = FXSYS_atoi(word); |
| 535 if (start_objnum >= (1 << 20)) | 522 if (start_objnum >= (1 << 20)) |
| 536 return false; | 523 return false; |
| 537 | 524 |
| 538 FX_DWORD count = m_Syntax.GetDirectNum(); | 525 FX_DWORD count = m_Syntax.GetDirectNum(); |
| 539 m_Syntax.ToNextWord(); | 526 m_Syntax.ToNextWord(); |
| 540 SavedPos = m_Syntax.SavePos(); | 527 SavedPos = m_Syntax.SavePos(); |
| 541 FX_BOOL bFirstItem = FALSE; | 528 FX_BOOL bFirstItem = FALSE; |
| 542 int32_t recordsize = 20; | 529 const int32_t recordsize = 20; |
| 543 if (bFirst) | 530 if (bFirst) |
| 544 bFirstItem = TRUE; | 531 bFirstItem = TRUE; |
| 545 m_dwXrefStartObjNum = start_objnum; | 532 m_dwXrefStartObjNum = start_objnum; |
| 546 if (!bSkip) { | 533 if (!bSkip) { |
| 547 char* pBuf = FX_Alloc(char, 1024 * recordsize + 1); | 534 std::vector<char> buf(1024 * recordsize + 1); |
| 548 pBuf[1024 * recordsize] = '\0'; | 535 buf[1024 * recordsize] = '\0'; |
| 549 int32_t nBlocks = count / 1024 + 1; | 536 int32_t nBlocks = count / 1024 + 1; |
| 550 FX_BOOL bFirstBlock = TRUE; | 537 FX_BOOL bFirstBlock = TRUE; |
| 551 for (int32_t block = 0; block < nBlocks; block++) { | 538 for (int32_t block = 0; block < nBlocks; block++) { |
| 552 int32_t block_size = block == nBlocks - 1 ? count % 1024 : 1024; | 539 int32_t block_size = block == nBlocks - 1 ? count % 1024 : 1024; |
| 553 m_Syntax.ReadBlock((uint8_t*)pBuf, block_size * recordsize); | 540 m_Syntax.ReadBlock((uint8_t*)buf.data(), block_size * recordsize); |
| 554 for (int32_t i = 0; i < block_size; i++) { | 541 for (int32_t i = 0; i < block_size; i++) { |
| 555 FX_DWORD objnum = start_objnum + block * 1024 + i; | 542 FX_DWORD objnum = start_objnum + block * 1024 + i; |
| 556 char* pEntry = pBuf + i * recordsize; | 543 char* pEntry = buf.data() + i * recordsize; |
| 557 if (pEntry[17] == 'f') { | 544 if (pEntry[17] == 'f') { |
| 558 if (bFirstItem) { | 545 if (bFirstItem) { |
| 559 objnum = 0; | 546 objnum = 0; |
| 560 bFirstItem = FALSE; | 547 bFirstItem = FALSE; |
| 561 } | 548 } |
| 562 if (bFirstBlock) { | 549 if (bFirstBlock) { |
| 563 FX_FILESIZE offset = (FX_FILESIZE)FXSYS_atoi64(pEntry); | 550 FX_FILESIZE offset = (FX_FILESIZE)FXSYS_atoi64(pEntry); |
| 564 int32_t version = FXSYS_atoi(pEntry + 11); | 551 int32_t version = FXSYS_atoi(pEntry + 11); |
| 565 if (offset == 0 && version == 65535 && start_objnum != 0) { | 552 if (offset == 0 && version == 65535 && start_objnum != 0) { |
| 566 start_objnum--; | 553 start_objnum--; |
| 567 objnum = 0; | 554 objnum = 0; |
| 568 } | 555 } |
| 569 } | 556 } |
| 570 m_CrossRef.SetAtGrow(objnum, 0); | 557 m_CrossRef.SetAtGrow(objnum, 0); |
| 571 m_V5Type.SetAtGrow(objnum, 0); | 558 m_V5Type.SetAtGrow(objnum, 0); |
| 572 } else { | 559 } else { |
| 573 FX_FILESIZE offset = (FX_FILESIZE)FXSYS_atoi64(pEntry); | 560 FX_FILESIZE offset = (FX_FILESIZE)FXSYS_atoi64(pEntry); |
| 574 if (offset == 0) { | 561 if (offset == 0) { |
| 575 for (int32_t c = 0; c < 10; c++) { | 562 for (int32_t c = 0; c < 10; c++) { |
| 576 if (pEntry[c] < '0' || pEntry[c] > '9') { | 563 if (pEntry[c] < '0' || pEntry[c] > '9') { |
| 577 FX_Free(pBuf); | |
| 578 return false; | 564 return false; |
| 579 } | 565 } |
| 580 } | 566 } |
| 581 } | 567 } |
| 582 m_CrossRef.SetAtGrow(objnum, offset); | 568 m_CrossRef.SetAtGrow(objnum, offset); |
| 583 int32_t version = FXSYS_atoi(pEntry + 11); | 569 int32_t version = FXSYS_atoi(pEntry + 11); |
| 584 if (version >= 1) { | 570 if (version >= 1) { |
| 585 m_bVersionUpdated = TRUE; | 571 m_bVersionUpdated = TRUE; |
| 586 } | 572 } |
| 587 m_ObjVersion.SetAtGrow(objnum, version); | 573 m_ObjVersion.SetAtGrow(objnum, version); |
| 588 if (m_CrossRef[objnum] < m_Syntax.m_FileLen && | 574 if (m_CrossRef[objnum] < m_Syntax.m_FileLen && |
| 589 !FindPosInOffsets(m_CrossRef[objnum])) { | 575 !FindPosInOffsets(m_CrossRef[objnum])) { |
| 590 m_SortedOffset.Add(m_CrossRef[objnum]); | 576 m_SortedOffset.Add(m_CrossRef[objnum]); |
| 591 } | 577 } |
| 592 m_V5Type.SetAtGrow(objnum, 1); | 578 m_V5Type.SetAtGrow(objnum, 1); |
| 593 } | 579 } |
| 594 if (bFirstBlock) { | 580 if (bFirstBlock) { |
| 595 bFirstBlock = FALSE; | 581 bFirstBlock = FALSE; |
| 596 } | 582 } |
| 597 } | 583 } |
| 598 } | 584 } |
| 599 FX_Free(pBuf); | |
| 600 } | 585 } |
| 601 m_Syntax.RestorePos(SavedPos + count * recordsize); | 586 m_Syntax.RestorePos(SavedPos + count * recordsize); |
| 602 } | 587 } |
| 603 return !streampos || LoadCrossRefV5(streampos, streampos, FALSE); | 588 return !streampos || LoadCrossRefV5(streampos, streampos, FALSE); |
| 604 } | 589 } |
| 605 | 590 |
| 606 FX_BOOL CPDF_Parser::LoadAllCrossRefV5(FX_FILESIZE xrefpos) { | 591 FX_BOOL CPDF_Parser::LoadAllCrossRefV5(FX_FILESIZE xrefpos) { |
| 607 if (!LoadCrossRefV5(xrefpos, xrefpos, TRUE)) { | 592 if (!LoadCrossRefV5(xrefpos, xrefpos, TRUE)) { |
| 608 return FALSE; | 593 return FALSE; |
| 609 } | 594 } |
| (...skipping 859 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1469 return nullptr; | 1454 return nullptr; |
| 1470 | 1455 |
| 1471 nonstd::unique_ptr<CPDF_Object, ReleaseDeleter<CPDF_Object>> pObj( | 1456 nonstd::unique_ptr<CPDF_Object, ReleaseDeleter<CPDF_Object>> pObj( |
| 1472 m_Syntax.GetObject(m_pDocument, 0, 0, 0)); | 1457 m_Syntax.GetObject(m_pDocument, 0, 0, 0)); |
| 1473 if (!ToDictionary(pObj.get())) | 1458 if (!ToDictionary(pObj.get())) |
| 1474 return nullptr; | 1459 return nullptr; |
| 1475 return pObj.release()->AsDictionary(); | 1460 return pObj.release()->AsDictionary(); |
| 1476 } | 1461 } |
| 1477 | 1462 |
| 1478 FX_DWORD CPDF_Parser::GetPermissions(FX_BOOL bCheckRevision) { | 1463 FX_DWORD CPDF_Parser::GetPermissions(FX_BOOL bCheckRevision) { |
| 1479 if (m_pSecurityHandler == NULL) { | 1464 if (!m_pSecurityHandler) { |
| 1480 return (FX_DWORD)-1; | 1465 return (FX_DWORD)-1; |
| 1481 } | 1466 } |
| 1482 FX_DWORD dwPermission = m_pSecurityHandler->GetPermissions(); | 1467 FX_DWORD dwPermission = m_pSecurityHandler->GetPermissions(); |
| 1483 if (m_pEncryptDict && | 1468 if (m_pEncryptDict && |
| 1484 m_pEncryptDict->GetString(FX_BSTRC("Filter")) == FX_BSTRC("Standard")) { | 1469 m_pEncryptDict->GetString(FX_BSTRC("Filter")) == FX_BSTRC("Standard")) { |
| 1485 dwPermission &= 0xFFFFFFFC; | 1470 dwPermission &= 0xFFFFFFFC; |
| 1486 dwPermission |= 0xFFFFF0C0; | 1471 dwPermission |= 0xFFFFF0C0; |
| 1487 if (bCheckRevision && m_pEncryptDict->GetInteger(FX_BSTRC("R")) == 2) { | 1472 if (bCheckRevision && m_pEncryptDict->GetInteger(FX_BSTRC("R")) == 2) { |
| 1488 dwPermission &= 0xFFFFF0FF; | 1473 dwPermission &= 0xFFFFF0FF; |
| 1489 } | 1474 } |
| 1490 } | 1475 } |
| 1491 return dwPermission; | 1476 return dwPermission; |
| 1492 } | 1477 } |
| 1493 FX_BOOL CPDF_Parser::IsOwner() { | 1478 FX_BOOL CPDF_Parser::IsOwner() { |
| 1494 return m_pSecurityHandler == NULL ? TRUE : m_pSecurityHandler->IsOwner(); | 1479 return m_pSecurityHandler == NULL ? TRUE : m_pSecurityHandler->IsOwner(); |
| 1495 } | 1480 } |
| 1496 void CPDF_Parser::SetSecurityHandler(CPDF_SecurityHandler* pSecurityHandler, | 1481 void CPDF_Parser::SetSecurityHandler(CPDF_SecurityHandler* pSecurityHandler, |
| 1497 FX_BOOL bForced) { | 1482 FX_BOOL bForced) { |
| 1498 ASSERT(m_pSecurityHandler == NULL); | |
| 1499 if (!m_bForceUseSecurityHandler) { | |
| 1500 delete m_pSecurityHandler; | |
| 1501 m_pSecurityHandler = NULL; | |
| 1502 } | |
| 1503 m_bForceUseSecurityHandler = bForced; | 1483 m_bForceUseSecurityHandler = bForced; |
| 1504 m_pSecurityHandler = pSecurityHandler; | 1484 m_pSecurityHandler.reset(pSecurityHandler); |
| 1505 if (m_bForceUseSecurityHandler) { | 1485 if (m_bForceUseSecurityHandler) { |
| 1506 return; | 1486 return; |
| 1507 } | 1487 } |
| 1508 m_Syntax.m_pCryptoHandler = pSecurityHandler->CreateCryptoHandler(); | 1488 m_Syntax.m_pCryptoHandler.reset(pSecurityHandler->CreateCryptoHandler()); |
| 1509 m_Syntax.m_pCryptoHandler->Init(NULL, pSecurityHandler); | 1489 m_Syntax.m_pCryptoHandler->Init(NULL, pSecurityHandler); |
| 1510 } | 1490 } |
| 1511 FX_BOOL CPDF_Parser::IsLinearizedFile(IFX_FileRead* pFileAccess, | 1491 FX_BOOL CPDF_Parser::IsLinearizedFile(IFX_FileRead* pFileAccess, |
| 1512 FX_DWORD offset) { | 1492 FX_DWORD offset) { |
| 1513 m_Syntax.InitParser(pFileAccess, offset); | 1493 m_Syntax.InitParser(pFileAccess, offset); |
| 1514 m_Syntax.RestorePos(m_Syntax.m_HeaderOffset + 9); | 1494 m_Syntax.RestorePos(m_Syntax.m_HeaderOffset + 9); |
| 1515 FX_FILESIZE SavedPos = m_Syntax.SavePos(); | 1495 FX_FILESIZE SavedPos = m_Syntax.SavePos(); |
| 1516 FX_BOOL bIsNumber; | 1496 FX_BOOL bIsNumber; |
| 1517 CFX_ByteString word = m_Syntax.GetNextWord(bIsNumber); | 1497 CFX_ByteString word = m_Syntax.GetNextWord(bIsNumber); |
| 1518 if (!bIsNumber) { | 1498 if (!bIsNumber) { |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1697 sizeof(FX_FILESIZE), CompareFileSize); | 1677 sizeof(FX_FILESIZE), CompareFileSize); |
| 1698 m_Syntax.m_MetadataObjnum = dwSaveMetadataObjnum; | 1678 m_Syntax.m_MetadataObjnum = dwSaveMetadataObjnum; |
| 1699 return PDFPARSE_ERROR_SUCCESS; | 1679 return PDFPARSE_ERROR_SUCCESS; |
| 1700 } | 1680 } |
| 1701 | 1681 |
| 1702 // static | 1682 // static |
| 1703 int CPDF_SyntaxParser::s_CurrentRecursionDepth = 0; | 1683 int CPDF_SyntaxParser::s_CurrentRecursionDepth = 0; |
| 1704 | 1684 |
| 1705 CPDF_SyntaxParser::CPDF_SyntaxParser() { | 1685 CPDF_SyntaxParser::CPDF_SyntaxParser() { |
| 1706 m_pFileAccess = NULL; | 1686 m_pFileAccess = NULL; |
| 1707 m_pCryptoHandler = NULL; | |
| 1708 m_pFileBuf = NULL; | 1687 m_pFileBuf = NULL; |
| 1709 m_BufSize = CPDF_ModuleMgr::kFileBufSize; | 1688 m_BufSize = CPDF_ModuleMgr::kFileBufSize; |
| 1710 m_pFileBuf = NULL; | 1689 m_pFileBuf = NULL; |
| 1711 m_MetadataObjnum = 0; | 1690 m_MetadataObjnum = 0; |
| 1712 m_dwWordPos = 0; | 1691 m_dwWordPos = 0; |
| 1713 m_bFileStream = FALSE; | 1692 m_bFileStream = FALSE; |
| 1714 } | 1693 } |
| 1715 CPDF_SyntaxParser::~CPDF_SyntaxParser() { | 1694 CPDF_SyntaxParser::~CPDF_SyntaxParser() { |
| 1716 FX_Free(m_pFileBuf); | 1695 FX_Free(m_pFileBuf); |
| 1717 } | 1696 } |
| (...skipping 684 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2402 } | 2381 } |
| 2403 // Locate the start of stream. | 2382 // Locate the start of stream. |
| 2404 ToNextLine(); | 2383 ToNextLine(); |
| 2405 FX_FILESIZE streamStartPos = m_Pos; | 2384 FX_FILESIZE streamStartPos = m_Pos; |
| 2406 if (pContext) { | 2385 if (pContext) { |
| 2407 pContext->m_DataStart = streamStartPos; | 2386 pContext->m_DataStart = streamStartPos; |
| 2408 } | 2387 } |
| 2409 const unsigned int ENDSTREAM_LEN = sizeof("endstream") - 1; | 2388 const unsigned int ENDSTREAM_LEN = sizeof("endstream") - 1; |
| 2410 const unsigned int ENDOBJ_LEN = sizeof("endobj") - 1; | 2389 const unsigned int ENDOBJ_LEN = sizeof("endobj") - 1; |
| 2411 CPDF_CryptoHandler* pCryptoHandler = | 2390 CPDF_CryptoHandler* pCryptoHandler = |
| 2412 objnum == (FX_DWORD)m_MetadataObjnum ? nullptr : m_pCryptoHandler; | 2391 objnum == (FX_DWORD)m_MetadataObjnum ? nullptr : m_pCryptoHandler.get(); |
| 2413 if (!pCryptoHandler) { | 2392 if (!pCryptoHandler) { |
| 2414 FX_BOOL bSearchForKeyword = TRUE; | 2393 FX_BOOL bSearchForKeyword = TRUE; |
| 2415 if (len >= 0) { | 2394 if (len >= 0) { |
| 2416 pdfium::base::CheckedNumeric<FX_FILESIZE> pos = m_Pos; | 2395 pdfium::base::CheckedNumeric<FX_FILESIZE> pos = m_Pos; |
| 2417 pos += len; | 2396 pos += len; |
| 2418 if (pos.IsValid() && pos.ValueOrDie() < m_FileLen) { | 2397 if (pos.IsValid() && pos.ValueOrDie() < m_FileLen) { |
| 2419 m_Pos = pos.ValueOrDie(); | 2398 m_Pos = pos.ValueOrDie(); |
| 2420 } | 2399 } |
| 2421 m_Pos += ReadEOLMarkers(m_Pos); | 2400 m_Pos += ReadEOLMarkers(m_Pos); |
| 2422 FXSYS_memset(m_WordBuffer, 0, ENDSTREAM_LEN + 1); | 2401 FXSYS_memset(m_WordBuffer, 0, ENDSTREAM_LEN + 1); |
| (...skipping 2185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4608 return FALSE; | 4587 return FALSE; |
| 4609 } | 4588 } |
| 4610 CPDF_PageNode::~CPDF_PageNode() { | 4589 CPDF_PageNode::~CPDF_PageNode() { |
| 4611 int32_t iSize = m_childNode.GetSize(); | 4590 int32_t iSize = m_childNode.GetSize(); |
| 4612 for (int32_t i = 0; i < iSize; ++i) { | 4591 for (int32_t i = 0; i < iSize; ++i) { |
| 4613 CPDF_PageNode* pNode = (CPDF_PageNode*)m_childNode[i]; | 4592 CPDF_PageNode* pNode = (CPDF_PageNode*)m_childNode[i]; |
| 4614 delete pNode; | 4593 delete pNode; |
| 4615 } | 4594 } |
| 4616 m_childNode.RemoveAll(); | 4595 m_childNode.RemoveAll(); |
| 4617 } | 4596 } |
| OLD | NEW |