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 "parser_int.h" | 7 #include "parser_int.h" |
8 | 8 |
9 #include <set> | 9 #include <set> |
10 #include <utility> | 10 #include <utility> |
(...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
320 if (filter == "Standard") { | 320 if (filter == "Standard") { |
321 pSecurityHandler.reset(FPDF_CreateStandardSecurityHandler()); | 321 pSecurityHandler.reset(FPDF_CreateStandardSecurityHandler()); |
322 err = PDFPARSE_ERROR_PASSWORD; | 322 err = PDFPARSE_ERROR_PASSWORD; |
323 } | 323 } |
324 if (!pSecurityHandler) { | 324 if (!pSecurityHandler) { |
325 return PDFPARSE_ERROR_HANDLER; | 325 return PDFPARSE_ERROR_HANDLER; |
326 } | 326 } |
327 if (!pSecurityHandler->OnInit(this, m_pEncryptDict)) { | 327 if (!pSecurityHandler->OnInit(this, m_pEncryptDict)) { |
328 return err; | 328 return err; |
329 } | 329 } |
330 m_pSecurityHandler = nonstd::move(pSecurityHandler); | 330 m_pSecurityHandler = std::move(pSecurityHandler); |
331 nonstd::unique_ptr<CPDF_CryptoHandler> pCryptoHandler( | 331 nonstd::unique_ptr<CPDF_CryptoHandler> pCryptoHandler( |
332 m_pSecurityHandler->CreateCryptoHandler()); | 332 m_pSecurityHandler->CreateCryptoHandler()); |
333 if (!pCryptoHandler->Init(m_pEncryptDict, m_pSecurityHandler.get())) { | 333 if (!pCryptoHandler->Init(m_pEncryptDict, m_pSecurityHandler.get())) { |
334 return PDFPARSE_ERROR_HANDLER; | 334 return PDFPARSE_ERROR_HANDLER; |
335 } | 335 } |
336 m_Syntax.SetEncrypt(pCryptoHandler.release()); | 336 m_Syntax.SetEncrypt(pCryptoHandler.release()); |
337 } | 337 } |
338 return PDFPARSE_ERROR_SUCCESS; | 338 return PDFPARSE_ERROR_SUCCESS; |
339 } | 339 } |
340 void CPDF_Parser::ReleaseEncryptHandler() { | 340 void CPDF_Parser::ReleaseEncryptHandler() { |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
449 FXSYS_bsearch(&pos, m_SortedOffset.GetData(), m_SortedOffset.GetSize(), | 449 FXSYS_bsearch(&pos, m_SortedOffset.GetData(), m_SortedOffset.GetSize(), |
450 sizeof(FX_FILESIZE), CompareFileSize); | 450 sizeof(FX_FILESIZE), CompareFileSize); |
451 if (!pResult) { | 451 if (!pResult) { |
452 m_SortedOffset.Add(pos); | 452 m_SortedOffset.Add(pos); |
453 } | 453 } |
454 FX_DWORD start_objnum = 0; | 454 FX_DWORD start_objnum = 0; |
455 FX_DWORD count = dwObjCount; | 455 FX_DWORD count = dwObjCount; |
456 FX_FILESIZE SavedPos = m_Syntax.SavePos(); | 456 FX_FILESIZE SavedPos = m_Syntax.SavePos(); |
457 const int32_t recordsize = 20; | 457 const int32_t recordsize = 20; |
458 std::vector<char> buf(1024 * recordsize + 1); | 458 std::vector<char> buf(1024 * recordsize + 1); |
459 char* pBuf = pdfium::vector_as_array(&buf); | 459 buf[1024 * recordsize] = '\0'; |
460 pBuf[1024 * recordsize] = '\0'; | |
461 int32_t nBlocks = count / 1024 + 1; | 460 int32_t nBlocks = count / 1024 + 1; |
462 for (int32_t block = 0; block < nBlocks; block++) { | 461 for (int32_t block = 0; block < nBlocks; block++) { |
463 int32_t block_size = block == nBlocks - 1 ? count % 1024 : 1024; | 462 int32_t block_size = block == nBlocks - 1 ? count % 1024 : 1024; |
464 FX_DWORD dwReadSize = block_size * recordsize; | 463 FX_DWORD dwReadSize = block_size * recordsize; |
465 if ((FX_FILESIZE)(dwStartPos + dwReadSize) > m_Syntax.m_FileLen) { | 464 if ((FX_FILESIZE)(dwStartPos + dwReadSize) > m_Syntax.m_FileLen) { |
466 return FALSE; | 465 return FALSE; |
467 } | 466 } |
468 if (!m_Syntax.ReadBlock(reinterpret_cast<uint8_t*>(pBuf), dwReadSize)) { | 467 if (!m_Syntax.ReadBlock(reinterpret_cast<uint8_t*>(buf.data()), |
| 468 dwReadSize)) { |
469 return FALSE; | 469 return FALSE; |
470 } | 470 } |
471 for (int32_t i = 0; i < block_size; i++) { | 471 for (int32_t i = 0; i < block_size; i++) { |
472 FX_DWORD objnum = start_objnum + block * 1024 + i; | 472 FX_DWORD objnum = start_objnum + block * 1024 + i; |
473 char* pEntry = pBuf + i * recordsize; | 473 char* pEntry = &buf[i * recordsize]; |
474 if (pEntry[17] == 'f') { | 474 if (pEntry[17] == 'f') { |
475 m_ObjectInfo[objnum].pos = 0; | 475 m_ObjectInfo[objnum].pos = 0; |
476 m_V5Type.SetAtGrow(objnum, 0); | 476 m_V5Type.SetAtGrow(objnum, 0); |
477 } else { | 477 } else { |
478 int32_t offset = FXSYS_atoi(pEntry); | 478 int32_t offset = FXSYS_atoi(pEntry); |
479 if (offset == 0) { | 479 if (offset == 0) { |
480 for (int32_t c = 0; c < 10; c++) { | 480 for (int32_t c = 0; c < 10; c++) { |
481 if (!std::isdigit(pEntry[c])) | 481 if (!std::isdigit(pEntry[c])) |
482 return FALSE; | 482 return FALSE; |
483 } | 483 } |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
537 if (start_objnum >= kMaxObjectNumber) | 537 if (start_objnum >= kMaxObjectNumber) |
538 return false; | 538 return false; |
539 | 539 |
540 FX_DWORD count = m_Syntax.GetDirectNum(); | 540 FX_DWORD count = m_Syntax.GetDirectNum(); |
541 m_Syntax.ToNextWord(); | 541 m_Syntax.ToNextWord(); |
542 SavedPos = m_Syntax.SavePos(); | 542 SavedPos = m_Syntax.SavePos(); |
543 const int32_t recordsize = 20; | 543 const int32_t recordsize = 20; |
544 m_dwXrefStartObjNum = start_objnum; | 544 m_dwXrefStartObjNum = start_objnum; |
545 if (!bSkip) { | 545 if (!bSkip) { |
546 std::vector<char> buf(1024 * recordsize + 1); | 546 std::vector<char> buf(1024 * recordsize + 1); |
547 char* pBuf = pdfium::vector_as_array(&buf); | 547 buf[1024 * recordsize] = '\0'; |
548 pBuf[1024 * recordsize] = '\0'; | |
549 int32_t nBlocks = count / 1024 + 1; | 548 int32_t nBlocks = count / 1024 + 1; |
550 for (int32_t block = 0; block < nBlocks; block++) { | 549 for (int32_t block = 0; block < nBlocks; block++) { |
551 int32_t block_size = block == nBlocks - 1 ? count % 1024 : 1024; | 550 int32_t block_size = block == nBlocks - 1 ? count % 1024 : 1024; |
552 m_Syntax.ReadBlock(reinterpret_cast<uint8_t*>(pBuf), | 551 m_Syntax.ReadBlock(reinterpret_cast<uint8_t*>(buf.data()), |
553 block_size * recordsize); | 552 block_size * recordsize); |
554 for (int32_t i = 0; i < block_size; i++) { | 553 for (int32_t i = 0; i < block_size; i++) { |
555 FX_DWORD objnum = start_objnum + block * 1024 + i; | 554 FX_DWORD objnum = start_objnum + block * 1024 + i; |
556 char* pEntry = pBuf + i * recordsize; | 555 char* pEntry = &buf[i * recordsize]; |
557 if (pEntry[17] == 'f') { | 556 if (pEntry[17] == 'f') { |
558 m_ObjectInfo[objnum].pos = 0; | 557 m_ObjectInfo[objnum].pos = 0; |
559 m_V5Type.SetAtGrow(objnum, 0); | 558 m_V5Type.SetAtGrow(objnum, 0); |
560 } else { | 559 } else { |
561 FX_FILESIZE offset = (FX_FILESIZE)FXSYS_atoi64(pEntry); | 560 FX_FILESIZE offset = (FX_FILESIZE)FXSYS_atoi64(pEntry); |
562 if (offset == 0) { | 561 if (offset == 0) { |
563 for (int32_t c = 0; c < 10; c++) { | 562 for (int32_t c = 0; c < 10; c++) { |
564 if (!std::isdigit(pEntry[c])) | 563 if (!std::isdigit(pEntry[c])) |
565 return false; | 564 return false; |
566 } | 565 } |
(...skipping 3032 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3599 if (!IsDataAvail(szHSStart, szHSLength, pHints)) { | 3598 if (!IsDataAvail(szHSStart, szHSLength, pHints)) { |
3600 return FALSE; | 3599 return FALSE; |
3601 } | 3600 } |
3602 m_syntaxParser.InitParser(m_pFileRead, m_dwHeaderOffset); | 3601 m_syntaxParser.InitParser(m_pFileRead, m_dwHeaderOffset); |
3603 nonstd::unique_ptr<CPDF_HintTables> pHintTables( | 3602 nonstd::unique_ptr<CPDF_HintTables> pHintTables( |
3604 new CPDF_HintTables(this, pDict)); | 3603 new CPDF_HintTables(this, pDict)); |
3605 nonstd::unique_ptr<CPDF_Object, ReleaseDeleter<CPDF_Object>> pHintStream( | 3604 nonstd::unique_ptr<CPDF_Object, ReleaseDeleter<CPDF_Object>> pHintStream( |
3606 ParseIndirectObjectAt(szHSStart, 0)); | 3605 ParseIndirectObjectAt(szHSStart, 0)); |
3607 CPDF_Stream* pStream = ToStream(pHintStream.get()); | 3606 CPDF_Stream* pStream = ToStream(pHintStream.get()); |
3608 if (pStream && pHintTables->LoadHintStream(pStream)) | 3607 if (pStream && pHintTables->LoadHintStream(pStream)) |
3609 m_pHintTables = nonstd::move(pHintTables); | 3608 m_pHintTables = std::move(pHintTables); |
3610 | 3609 |
3611 m_docStatus = PDF_DATAAVAIL_DONE; | 3610 m_docStatus = PDF_DATAAVAIL_DONE; |
3612 return TRUE; | 3611 return TRUE; |
3613 } | 3612 } |
3614 CPDF_Object* CPDF_DataAvail::ParseIndirectObjectAt( | 3613 CPDF_Object* CPDF_DataAvail::ParseIndirectObjectAt( |
3615 FX_FILESIZE pos, | 3614 FX_FILESIZE pos, |
3616 FX_DWORD objnum, | 3615 FX_DWORD objnum, |
3617 CPDF_IndirectObjects* pObjList) { | 3616 CPDF_IndirectObjects* pObjList) { |
3618 FX_FILESIZE SavedPos = m_syntaxParser.SavePos(); | 3617 FX_FILESIZE SavedPos = m_syntaxParser.SavePos(); |
3619 m_syntaxParser.RestorePos(pos); | 3618 m_syntaxParser.RestorePos(pos); |
(...skipping 1366 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4986 if (!m_pLinearizedDict) | 4985 if (!m_pLinearizedDict) |
4987 return -1; | 4986 return -1; |
4988 CPDF_Array* pRange = m_pLinearizedDict->GetArray("H"); | 4987 CPDF_Array* pRange = m_pLinearizedDict->GetArray("H"); |
4989 if (!pRange) | 4988 if (!pRange) |
4990 return -1; | 4989 return -1; |
4991 CPDF_Object* pStreamLen = pRange->GetElementValue(1); | 4990 CPDF_Object* pStreamLen = pRange->GetElementValue(1); |
4992 if (!pStreamLen) | 4991 if (!pStreamLen) |
4993 return -1; | 4992 return -1; |
4994 return pStreamLen->GetInteger(); | 4993 return pStreamLen->GetInteger(); |
4995 } | 4994 } |
OLD | NEW |