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