OLD | NEW |
1 // Copyright 2016 PDFium Authors. All rights reserved. | 1 // Copyright 2016 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 "core/fpdfapi/parser/cpdf_syntax_parser.h" | 7 #include "core/fpdfapi/parser/cpdf_syntax_parser.h" |
8 | 8 |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
418 | 418 |
419 if (word[0] == '/') { | 419 if (word[0] == '/') { |
420 return new CPDF_Name(MaybeIntern( | 420 return new CPDF_Name(MaybeIntern( |
421 PDF_NameDecode(CFX_ByteStringC(m_WordBuffer + 1, m_WordSize - 1)))); | 421 PDF_NameDecode(CFX_ByteStringC(m_WordBuffer + 1, m_WordSize - 1)))); |
422 } | 422 } |
423 | 423 |
424 if (word == "<<") { | 424 if (word == "<<") { |
425 int32_t nKeys = 0; | 425 int32_t nKeys = 0; |
426 FX_FILESIZE dwSignValuePos = 0; | 426 FX_FILESIZE dwSignValuePos = 0; |
427 | 427 |
428 std::unique_ptr<CPDF_Dictionary, ReleaseDeleter<CPDF_Dictionary>> pDict( | 428 std::unique_ptr<CPDF_Dictionary> pDict(new CPDF_Dictionary(m_pPool)); |
429 new CPDF_Dictionary(m_pPool)); | |
430 while (1) { | 429 while (1) { |
431 CFX_ByteString key = GetNextWord(nullptr); | 430 CFX_ByteString key = GetNextWord(nullptr); |
432 if (key.IsEmpty()) | 431 if (key.IsEmpty()) |
433 return nullptr; | 432 return nullptr; |
434 | 433 |
435 FX_FILESIZE SavedPos = m_Pos - key.GetLength(); | 434 FX_FILESIZE SavedPos = m_Pos - key.GetLength(); |
436 if (key == ">>") | 435 if (key == ">>") |
437 break; | 436 break; |
438 | 437 |
439 if (key == "endobj") { | 438 if (key == "endobj") { |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
523 } | 522 } |
524 | 523 |
525 if (word == "<") { | 524 if (word == "<") { |
526 CFX_ByteString str = ReadHexString(); | 525 CFX_ByteString str = ReadHexString(); |
527 if (m_pCryptoHandler) | 526 if (m_pCryptoHandler) |
528 m_pCryptoHandler->Decrypt(objnum, gennum, str); | 527 m_pCryptoHandler->Decrypt(objnum, gennum, str); |
529 return new CPDF_String(MaybeIntern(str), true); | 528 return new CPDF_String(MaybeIntern(str), true); |
530 } | 529 } |
531 | 530 |
532 if (word == "[") { | 531 if (word == "[") { |
533 std::unique_ptr<CPDF_Array, ReleaseDeleter<CPDF_Array>> pArray( | 532 std::unique_ptr<CPDF_Array> pArray(new CPDF_Array); |
534 new CPDF_Array); | |
535 while (CPDF_Object* pObj = GetObject(pObjList, objnum, gennum, true)) | 533 while (CPDF_Object* pObj = GetObject(pObjList, objnum, gennum, true)) |
536 pArray->Add(pObj); | 534 pArray->Add(pObj); |
537 | 535 |
538 return m_WordBuffer[0] == ']' ? pArray.release() : nullptr; | 536 return m_WordBuffer[0] == ']' ? pArray.release() : nullptr; |
539 } | 537 } |
540 | 538 |
541 if (word[0] == '/') { | 539 if (word[0] == '/') { |
542 return new CPDF_Name(MaybeIntern( | 540 return new CPDF_Name(MaybeIntern( |
543 PDF_NameDecode(CFX_ByteStringC(m_WordBuffer + 1, m_WordSize - 1)))); | 541 PDF_NameDecode(CFX_ByteStringC(m_WordBuffer + 1, m_WordSize - 1)))); |
544 } | 542 } |
545 | 543 |
546 if (word == "<<") { | 544 if (word == "<<") { |
547 std::unique_ptr<CPDF_Dictionary, ReleaseDeleter<CPDF_Dictionary>> pDict( | 545 std::unique_ptr<CPDF_Dictionary> pDict(new CPDF_Dictionary(m_pPool)); |
548 new CPDF_Dictionary(m_pPool)); | |
549 while (1) { | 546 while (1) { |
550 FX_FILESIZE SavedPos = m_Pos; | 547 FX_FILESIZE SavedPos = m_Pos; |
551 CFX_ByteString key = GetNextWord(nullptr); | 548 CFX_ByteString key = GetNextWord(nullptr); |
552 if (key.IsEmpty()) | 549 if (key.IsEmpty()) |
553 return nullptr; | 550 return nullptr; |
554 | 551 |
555 if (key == ">>") | 552 if (key == ">>") |
556 break; | 553 break; |
557 | 554 |
558 if (key == "endobj") { | 555 if (key == "endobj") { |
559 m_Pos = SavedPos; | 556 m_Pos = SavedPos; |
560 break; | 557 break; |
561 } | 558 } |
562 | 559 |
563 if (key[0] != '/') | 560 if (key[0] != '/') |
564 continue; | 561 continue; |
565 | 562 |
566 key = PDF_NameDecode(key); | 563 key = PDF_NameDecode(key); |
567 std::unique_ptr<CPDF_Object, ReleaseDeleter<CPDF_Object>> obj( | 564 std::unique_ptr<CPDF_Object> obj( |
568 GetObject(pObjList, objnum, gennum, true)); | 565 GetObject(pObjList, objnum, gennum, true)); |
569 if (!obj) { | 566 if (!obj) { |
570 uint8_t ch; | 567 uint8_t ch; |
571 while (GetNextChar(ch) && ch != 0x0A && ch != 0x0D) { | 568 while (GetNextChar(ch) && ch != 0x0A && ch != 0x0D) { |
572 continue; | 569 continue; |
573 } | 570 } |
574 return nullptr; | 571 return nullptr; |
575 } | 572 } |
576 | 573 |
577 if (key.GetLength() > 1) { | 574 if (key.GetLength() > 1) { |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
685 // Stop searching when "endobj" is found. | 682 // Stop searching when "endobj" is found. |
686 if (IsWholeWord(m_Pos - kEndObjStr.GetLength(), m_FileLen, kEndObjStr, | 683 if (IsWholeWord(m_Pos - kEndObjStr.GetLength(), m_FileLen, kEndObjStr, |
687 true)) { | 684 true)) { |
688 endObjOffset = m_Pos - streamStartPos - kEndObjStr.GetLength(); | 685 endObjOffset = m_Pos - streamStartPos - kEndObjStr.GetLength(); |
689 break; | 686 break; |
690 } | 687 } |
691 } | 688 } |
692 | 689 |
693 // Can't find "endstream" or "endobj". | 690 // Can't find "endstream" or "endobj". |
694 if (endStreamOffset < 0 && endObjOffset < 0) { | 691 if (endStreamOffset < 0 && endObjOffset < 0) { |
695 pDict->Release(); | 692 delete pDict; |
696 return nullptr; | 693 return nullptr; |
697 } | 694 } |
698 | 695 |
699 if (endStreamOffset < 0 && endObjOffset >= 0) { | 696 if (endStreamOffset < 0 && endObjOffset >= 0) { |
700 // Correct the position of end stream. | 697 // Correct the position of end stream. |
701 endStreamOffset = endObjOffset; | 698 endStreamOffset = endObjOffset; |
702 } else if (endStreamOffset >= 0 && endObjOffset < 0) { | 699 } else if (endStreamOffset >= 0 && endObjOffset < 0) { |
703 // Correct the position of end obj. | 700 // Correct the position of end obj. |
704 endObjOffset = endStreamOffset; | 701 endObjOffset = endStreamOffset; |
705 } else if (endStreamOffset > endObjOffset) { | 702 } else if (endStreamOffset > endObjOffset) { |
706 endStreamOffset = endObjOffset; | 703 endStreamOffset = endObjOffset; |
707 } | 704 } |
708 | 705 |
709 len = endStreamOffset; | 706 len = endStreamOffset; |
710 int numMarkers = ReadEOLMarkers(streamStartPos + endStreamOffset - 2); | 707 int numMarkers = ReadEOLMarkers(streamStartPos + endStreamOffset - 2); |
711 if (numMarkers == 2) { | 708 if (numMarkers == 2) { |
712 len -= 2; | 709 len -= 2; |
713 } else { | 710 } else { |
714 numMarkers = ReadEOLMarkers(streamStartPos + endStreamOffset - 1); | 711 numMarkers = ReadEOLMarkers(streamStartPos + endStreamOffset - 1); |
715 if (numMarkers == 1) { | 712 if (numMarkers == 1) { |
716 len -= 1; | 713 len -= 1; |
717 } | 714 } |
718 } | 715 } |
719 | 716 |
720 if (len < 0) { | 717 if (len < 0) { |
721 pDict->Release(); | 718 delete pDict; |
722 return nullptr; | 719 return nullptr; |
723 } | 720 } |
724 pDict->SetIntegerFor("Length", len); | 721 pDict->SetIntegerFor("Length", len); |
725 } | 722 } |
726 m_Pos = streamStartPos; | 723 m_Pos = streamStartPos; |
727 } | 724 } |
728 | 725 |
729 if (len < 0) { | 726 if (len < 0) { |
730 pDict->Release(); | 727 delete pDict; |
731 return nullptr; | 728 return nullptr; |
732 } | 729 } |
733 | 730 |
734 uint8_t* pData = nullptr; | 731 uint8_t* pData = nullptr; |
735 if (len > 0) { | 732 if (len > 0) { |
736 pData = FX_Alloc(uint8_t, len); | 733 pData = FX_Alloc(uint8_t, len); |
737 ReadBlock(pData, len); | 734 ReadBlock(pData, len); |
738 if (pCryptoHandler) { | 735 if (pCryptoHandler) { |
739 CFX_BinaryBuf dest_buf; | 736 CFX_BinaryBuf dest_buf; |
740 dest_buf.EstimateSize(pCryptoHandler->DecryptGetSize(len)); | 737 dest_buf.EstimateSize(pCryptoHandler->DecryptGetSize(len)); |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
915 } | 912 } |
916 | 913 |
917 void CPDF_SyntaxParser::SetEncrypt( | 914 void CPDF_SyntaxParser::SetEncrypt( |
918 std::unique_ptr<CPDF_CryptoHandler> pCryptoHandler) { | 915 std::unique_ptr<CPDF_CryptoHandler> pCryptoHandler) { |
919 m_pCryptoHandler = std::move(pCryptoHandler); | 916 m_pCryptoHandler = std::move(pCryptoHandler); |
920 } | 917 } |
921 | 918 |
922 CFX_ByteString CPDF_SyntaxParser::MaybeIntern(const CFX_ByteString& str) { | 919 CFX_ByteString CPDF_SyntaxParser::MaybeIntern(const CFX_ByteString& str) { |
923 return m_pPool ? m_pPool->Intern(str) : str; | 920 return m_pPool ? m_pPool->Intern(str) : str; |
924 } | 921 } |
OLD | NEW |