| 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 <algorithm> |
| 10 #include <utility> |
| 9 #include <vector> | 11 #include <vector> |
| 10 | 12 |
| 11 #include "core/fpdfapi/cpdf_modulemgr.h" | 13 #include "core/fpdfapi/cpdf_modulemgr.h" |
| 12 #include "core/fpdfapi/parser/cpdf_array.h" | 14 #include "core/fpdfapi/parser/cpdf_array.h" |
| 13 #include "core/fpdfapi/parser/cpdf_boolean.h" | 15 #include "core/fpdfapi/parser/cpdf_boolean.h" |
| 14 #include "core/fpdfapi/parser/cpdf_crypto_handler.h" | 16 #include "core/fpdfapi/parser/cpdf_crypto_handler.h" |
| 15 #include "core/fpdfapi/parser/cpdf_dictionary.h" | 17 #include "core/fpdfapi/parser/cpdf_dictionary.h" |
| 16 #include "core/fpdfapi/parser/cpdf_name.h" | 18 #include "core/fpdfapi/parser/cpdf_name.h" |
| 17 #include "core/fpdfapi/parser/cpdf_null.h" | 19 #include "core/fpdfapi/parser/cpdf_null.h" |
| 18 #include "core/fpdfapi/parser/cpdf_number.h" | 20 #include "core/fpdfapi/parser/cpdf_number.h" |
| (...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 451 | 453 |
| 452 if (key == "/Contents") | 454 if (key == "/Contents") |
| 453 dwSignValuePos = m_Pos; | 455 dwSignValuePos = m_Pos; |
| 454 | 456 |
| 455 std::unique_ptr<CPDF_Object> pObj = | 457 std::unique_ptr<CPDF_Object> pObj = |
| 456 GetObject(pObjList, objnum, gennum, true); | 458 GetObject(pObjList, objnum, gennum, true); |
| 457 if (!pObj) | 459 if (!pObj) |
| 458 continue; | 460 continue; |
| 459 | 461 |
| 460 CFX_ByteString keyNoSlash(key.raw_str() + 1, key.GetLength() - 1); | 462 CFX_ByteString keyNoSlash(key.raw_str() + 1, key.GetLength() - 1); |
| 461 pDict->SetFor(keyNoSlash, pObj.release()); | 463 pDict->SetFor(keyNoSlash, std::move(pObj)); |
| 462 } | 464 } |
| 463 | 465 |
| 464 // Only when this is a signature dictionary and has contents, we reset the | 466 // Only when this is a signature dictionary and has contents, we reset the |
| 465 // contents to the un-decrypted form. | 467 // contents to the un-decrypted form. |
| 466 if (pDict->IsSignatureDict() && dwSignValuePos) { | 468 if (pDict->IsSignatureDict() && dwSignValuePos) { |
| 467 CFX_AutoRestorer<FX_FILESIZE> save_pos(&m_Pos); | 469 CFX_AutoRestorer<FX_FILESIZE> save_pos(&m_Pos); |
| 468 m_Pos = dwSignValuePos; | 470 m_Pos = dwSignValuePos; |
| 469 pDict->SetFor("Contents", | 471 pDict->SetFor("Contents", GetObject(pObjList, objnum, gennum, false)); |
| 470 GetObject(pObjList, objnum, gennum, false).release()); | |
| 471 } | 472 } |
| 472 | 473 |
| 473 FX_FILESIZE SavedPos = m_Pos; | 474 FX_FILESIZE SavedPos = m_Pos; |
| 474 CFX_ByteString nextword = GetNextWord(nullptr); | 475 CFX_ByteString nextword = GetNextWord(nullptr); |
| 475 if (nextword != "stream") { | 476 if (nextword != "stream") { |
| 476 m_Pos = SavedPos; | 477 m_Pos = SavedPos; |
| 477 return std::move(pDict); | 478 return std::move(pDict); |
| 478 } | 479 } |
| 479 return ReadStream(pDict.release(), objnum, gennum); | 480 return ReadStream(pDict.release(), objnum, gennum); |
| 480 } | 481 } |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 569 if (!obj) { | 570 if (!obj) { |
| 570 uint8_t ch; | 571 uint8_t ch; |
| 571 while (GetNextChar(ch) && ch != 0x0A && ch != 0x0D) { | 572 while (GetNextChar(ch) && ch != 0x0A && ch != 0x0D) { |
| 572 continue; | 573 continue; |
| 573 } | 574 } |
| 574 return nullptr; | 575 return nullptr; |
| 575 } | 576 } |
| 576 | 577 |
| 577 if (key.GetLength() > 1) { | 578 if (key.GetLength() > 1) { |
| 578 pDict->SetFor(CFX_ByteString(key.c_str() + 1, key.GetLength() - 1), | 579 pDict->SetFor(CFX_ByteString(key.c_str() + 1, key.GetLength() - 1), |
| 579 obj.release()); | 580 std::move(obj)); |
| 580 } | 581 } |
| 581 } | 582 } |
| 582 | 583 |
| 583 FX_FILESIZE SavedPos = m_Pos; | 584 FX_FILESIZE SavedPos = m_Pos; |
| 584 CFX_ByteString nextword = GetNextWord(nullptr); | 585 CFX_ByteString nextword = GetNextWord(nullptr); |
| 585 if (nextword != "stream") { | 586 if (nextword != "stream") { |
| 586 m_Pos = SavedPos; | 587 m_Pos = SavedPos; |
| 587 return std::move(pDict); | 588 return std::move(pDict); |
| 588 } | 589 } |
| 589 | 590 |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 715 numMarkers = ReadEOLMarkers(streamStartPos + endStreamOffset - 1); | 716 numMarkers = ReadEOLMarkers(streamStartPos + endStreamOffset - 1); |
| 716 if (numMarkers == 1) { | 717 if (numMarkers == 1) { |
| 717 len -= 1; | 718 len -= 1; |
| 718 } | 719 } |
| 719 } | 720 } |
| 720 | 721 |
| 721 if (len < 0) { | 722 if (len < 0) { |
| 722 delete pDict; | 723 delete pDict; |
| 723 return nullptr; | 724 return nullptr; |
| 724 } | 725 } |
| 725 pDict->SetIntegerFor("Length", len); | 726 pDict->SetNewFor<CPDF_Number>("Length", static_cast<int>(len)); |
| 726 } | 727 } |
| 727 m_Pos = streamStartPos; | 728 m_Pos = streamStartPos; |
| 728 } | 729 } |
| 729 | 730 |
| 730 if (len < 0) { | 731 if (len < 0) { |
| 731 delete pDict; | 732 delete pDict; |
| 732 return nullptr; | 733 return nullptr; |
| 733 } | 734 } |
| 734 | 735 |
| 735 uint8_t* pData = nullptr; | 736 uint8_t* pData = nullptr; |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 911 if (limit && m_Pos == limit) | 912 if (limit && m_Pos == limit) |
| 912 return -1; | 913 return -1; |
| 913 } | 914 } |
| 914 return -1; | 915 return -1; |
| 915 } | 916 } |
| 916 | 917 |
| 917 void CPDF_SyntaxParser::SetEncrypt( | 918 void CPDF_SyntaxParser::SetEncrypt( |
| 918 std::unique_ptr<CPDF_CryptoHandler> pCryptoHandler) { | 919 std::unique_ptr<CPDF_CryptoHandler> pCryptoHandler) { |
| 919 m_pCryptoHandler = std::move(pCryptoHandler); | 920 m_pCryptoHandler = std::move(pCryptoHandler); |
| 920 } | 921 } |
| OLD | NEW |