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 423 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
434 | 434 |
435 if (word[0] == '/') { | 435 if (word[0] == '/') { |
436 return new CPDF_Name(MaybeIntern( | 436 return new CPDF_Name(MaybeIntern( |
437 PDF_NameDecode(CFX_ByteStringC(m_WordBuffer + 1, m_WordSize - 1)))); | 437 PDF_NameDecode(CFX_ByteStringC(m_WordBuffer + 1, m_WordSize - 1)))); |
438 } | 438 } |
439 | 439 |
440 if (word == "<<") { | 440 if (word == "<<") { |
441 int32_t nKeys = 0; | 441 int32_t nKeys = 0; |
442 FX_FILESIZE dwSignValuePos = 0; | 442 FX_FILESIZE dwSignValuePos = 0; |
443 | 443 |
444 std::unique_ptr<CPDF_Dictionary, ReleaseDeleter<CPDF_Dictionary>> pDict( | 444 std::unique_ptr<CPDF_Dictionary> pDict(new CPDF_Dictionary(m_pPool)); |
445 new CPDF_Dictionary(m_pPool)); | |
446 while (1) { | 445 while (1) { |
447 CFX_ByteString key = GetNextWord(nullptr); | 446 CFX_ByteString key = GetNextWord(nullptr); |
448 if (key.IsEmpty()) | 447 if (key.IsEmpty()) |
449 return nullptr; | 448 return nullptr; |
450 | 449 |
451 FX_FILESIZE SavedPos = m_Pos - key.GetLength(); | 450 FX_FILESIZE SavedPos = m_Pos - key.GetLength(); |
452 if (key == ">>") | 451 if (key == ">>") |
453 break; | 452 break; |
454 | 453 |
455 if (key == "endobj") { | 454 if (key == "endobj") { |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
539 } | 538 } |
540 | 539 |
541 if (word == "<") { | 540 if (word == "<") { |
542 CFX_ByteString str = ReadHexString(); | 541 CFX_ByteString str = ReadHexString(); |
543 if (m_pCryptoHandler) | 542 if (m_pCryptoHandler) |
544 m_pCryptoHandler->Decrypt(objnum, gennum, str); | 543 m_pCryptoHandler->Decrypt(objnum, gennum, str); |
545 return new CPDF_String(MaybeIntern(str), true); | 544 return new CPDF_String(MaybeIntern(str), true); |
546 } | 545 } |
547 | 546 |
548 if (word == "[") { | 547 if (word == "[") { |
549 std::unique_ptr<CPDF_Array, ReleaseDeleter<CPDF_Array>> pArray( | 548 std::unique_ptr<CPDF_Array> pArray(new CPDF_Array); |
550 new CPDF_Array); | |
551 while (CPDF_Object* pObj = GetObject(pObjList, objnum, gennum, true)) | 549 while (CPDF_Object* pObj = GetObject(pObjList, objnum, gennum, true)) |
552 pArray->Add(pObj); | 550 pArray->Add(pObj); |
553 | 551 |
554 return m_WordBuffer[0] == ']' ? pArray.release() : nullptr; | 552 return m_WordBuffer[0] == ']' ? pArray.release() : nullptr; |
555 } | 553 } |
556 | 554 |
557 if (word[0] == '/') { | 555 if (word[0] == '/') { |
558 return new CPDF_Name(MaybeIntern( | 556 return new CPDF_Name(MaybeIntern( |
559 PDF_NameDecode(CFX_ByteStringC(m_WordBuffer + 1, m_WordSize - 1)))); | 557 PDF_NameDecode(CFX_ByteStringC(m_WordBuffer + 1, m_WordSize - 1)))); |
560 } | 558 } |
561 | 559 |
562 if (word == "<<") { | 560 if (word == "<<") { |
563 std::unique_ptr<CPDF_Dictionary, ReleaseDeleter<CPDF_Dictionary>> pDict( | 561 std::unique_ptr<CPDF_Dictionary> pDict(new CPDF_Dictionary(m_pPool)); |
564 new CPDF_Dictionary(m_pPool)); | |
565 while (1) { | 562 while (1) { |
566 FX_FILESIZE SavedPos = m_Pos; | 563 FX_FILESIZE SavedPos = m_Pos; |
567 CFX_ByteString key = GetNextWord(nullptr); | 564 CFX_ByteString key = GetNextWord(nullptr); |
568 if (key.IsEmpty()) | 565 if (key.IsEmpty()) |
569 return nullptr; | 566 return nullptr; |
570 | 567 |
571 if (key == ">>") | 568 if (key == ">>") |
572 break; | 569 break; |
573 | 570 |
574 if (key == "endobj") { | 571 if (key == "endobj") { |
575 m_Pos = SavedPos; | 572 m_Pos = SavedPos; |
576 break; | 573 break; |
577 } | 574 } |
578 | 575 |
579 if (key[0] != '/') | 576 if (key[0] != '/') |
580 continue; | 577 continue; |
581 | 578 |
582 key = PDF_NameDecode(key); | 579 key = PDF_NameDecode(key); |
583 std::unique_ptr<CPDF_Object, ReleaseDeleter<CPDF_Object>> obj( | 580 std::unique_ptr<CPDF_Object> obj( |
584 GetObject(pObjList, objnum, gennum, true)); | 581 GetObject(pObjList, objnum, gennum, true)); |
585 if (!obj) { | 582 if (!obj) { |
586 uint8_t ch; | 583 uint8_t ch; |
587 while (GetNextChar(ch) && ch != 0x0A && ch != 0x0D) { | 584 while (GetNextChar(ch) && ch != 0x0A && ch != 0x0D) { |
588 continue; | 585 continue; |
589 } | 586 } |
590 return nullptr; | 587 return nullptr; |
591 } | 588 } |
592 | 589 |
593 if (key.GetLength() > 1) { | 590 if (key.GetLength() > 1) { |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
701 // Stop searching when "endobj" is found. | 698 // Stop searching when "endobj" is found. |
702 if (IsWholeWord(m_Pos - kEndObjStr.GetLength(), m_FileLen, kEndObjStr, | 699 if (IsWholeWord(m_Pos - kEndObjStr.GetLength(), m_FileLen, kEndObjStr, |
703 true)) { | 700 true)) { |
704 endObjOffset = m_Pos - streamStartPos - kEndObjStr.GetLength(); | 701 endObjOffset = m_Pos - streamStartPos - kEndObjStr.GetLength(); |
705 break; | 702 break; |
706 } | 703 } |
707 } | 704 } |
708 | 705 |
709 // Can't find "endstream" or "endobj". | 706 // Can't find "endstream" or "endobj". |
710 if (endStreamOffset < 0 && endObjOffset < 0) { | 707 if (endStreamOffset < 0 && endObjOffset < 0) { |
711 pDict->Release(); | 708 delete pDict; |
712 return nullptr; | 709 return nullptr; |
713 } | 710 } |
714 | 711 |
715 if (endStreamOffset < 0 && endObjOffset >= 0) { | 712 if (endStreamOffset < 0 && endObjOffset >= 0) { |
716 // Correct the position of end stream. | 713 // Correct the position of end stream. |
717 endStreamOffset = endObjOffset; | 714 endStreamOffset = endObjOffset; |
718 } else if (endStreamOffset >= 0 && endObjOffset < 0) { | 715 } else if (endStreamOffset >= 0 && endObjOffset < 0) { |
719 // Correct the position of end obj. | 716 // Correct the position of end obj. |
720 endObjOffset = endStreamOffset; | 717 endObjOffset = endStreamOffset; |
721 } else if (endStreamOffset > endObjOffset) { | 718 } else if (endStreamOffset > endObjOffset) { |
722 endStreamOffset = endObjOffset; | 719 endStreamOffset = endObjOffset; |
723 } | 720 } |
724 | 721 |
725 len = endStreamOffset; | 722 len = endStreamOffset; |
726 int numMarkers = ReadEOLMarkers(streamStartPos + endStreamOffset - 2); | 723 int numMarkers = ReadEOLMarkers(streamStartPos + endStreamOffset - 2); |
727 if (numMarkers == 2) { | 724 if (numMarkers == 2) { |
728 len -= 2; | 725 len -= 2; |
729 } else { | 726 } else { |
730 numMarkers = ReadEOLMarkers(streamStartPos + endStreamOffset - 1); | 727 numMarkers = ReadEOLMarkers(streamStartPos + endStreamOffset - 1); |
731 if (numMarkers == 1) { | 728 if (numMarkers == 1) { |
732 len -= 1; | 729 len -= 1; |
733 } | 730 } |
734 } | 731 } |
735 | 732 |
736 if (len < 0) { | 733 if (len < 0) { |
737 pDict->Release(); | 734 delete pDict; |
738 return nullptr; | 735 return nullptr; |
739 } | 736 } |
740 pDict->SetIntegerFor("Length", len); | 737 pDict->SetIntegerFor("Length", len); |
741 } | 738 } |
742 m_Pos = streamStartPos; | 739 m_Pos = streamStartPos; |
743 } | 740 } |
744 | 741 |
745 if (len < 0) { | 742 if (len < 0) { |
746 pDict->Release(); | 743 delete pDict; |
747 return nullptr; | 744 return nullptr; |
748 } | 745 } |
749 | 746 |
750 uint8_t* pData = nullptr; | 747 uint8_t* pData = nullptr; |
751 if (len > 0) { | 748 if (len > 0) { |
752 pData = FX_Alloc(uint8_t, len); | 749 pData = FX_Alloc(uint8_t, len); |
753 ReadBlock(pData, len); | 750 ReadBlock(pData, len); |
754 if (pCryptoHandler) { | 751 if (pCryptoHandler) { |
755 CFX_BinaryBuf dest_buf; | 752 CFX_BinaryBuf dest_buf; |
756 dest_buf.EstimateSize(pCryptoHandler->DecryptGetSize(len)); | 753 dest_buf.EstimateSize(pCryptoHandler->DecryptGetSize(len)); |
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
988 } | 985 } |
989 | 986 |
990 void CPDF_SyntaxParser::SetEncrypt( | 987 void CPDF_SyntaxParser::SetEncrypt( |
991 std::unique_ptr<CPDF_CryptoHandler> pCryptoHandler) { | 988 std::unique_ptr<CPDF_CryptoHandler> pCryptoHandler) { |
992 m_pCryptoHandler = std::move(pCryptoHandler); | 989 m_pCryptoHandler = std::move(pCryptoHandler); |
993 } | 990 } |
994 | 991 |
995 CFX_ByteString CPDF_SyntaxParser::MaybeIntern(const CFX_ByteString& str) { | 992 CFX_ByteString CPDF_SyntaxParser::MaybeIntern(const CFX_ByteString& str) { |
996 return m_pPool ? m_pPool->Intern(str) : str; | 993 return m_pPool ? m_pPool->Intern(str) : str; |
997 } | 994 } |
OLD | NEW |