| 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/fpdf_parser/cpdf_syntax_parser.h" | 7 #include "core/fpdfapi/fpdf_parser/cpdf_syntax_parser.h" |
| 8 | 8 |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 451 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 462 continue; | 462 continue; |
| 463 | 463 |
| 464 if (key == "/Contents") | 464 if (key == "/Contents") |
| 465 dwSignValuePos = m_Pos; | 465 dwSignValuePos = m_Pos; |
| 466 | 466 |
| 467 CPDF_Object* pObj = GetObject(pObjList, objnum, gennum, true); | 467 CPDF_Object* pObj = GetObject(pObjList, objnum, gennum, true); |
| 468 if (!pObj) | 468 if (!pObj) |
| 469 continue; | 469 continue; |
| 470 | 470 |
| 471 CFX_ByteString keyNoSlash(key.raw_str() + 1, key.GetLength() - 1); | 471 CFX_ByteString keyNoSlash(key.raw_str() + 1, key.GetLength() - 1); |
| 472 pDict->SetAt(keyNoSlash, pObj); | 472 pDict->SetFor(keyNoSlash, pObj); |
| 473 } | 473 } |
| 474 | 474 |
| 475 // Only when this is a signature dictionary and has contents, we reset the | 475 // Only when this is a signature dictionary and has contents, we reset the |
| 476 // contents to the un-decrypted form. | 476 // contents to the un-decrypted form. |
| 477 if (pDict->IsSignatureDict() && dwSignValuePos) { | 477 if (pDict->IsSignatureDict() && dwSignValuePos) { |
| 478 CFX_AutoRestorer<FX_FILESIZE> save_pos(&m_Pos); | 478 CFX_AutoRestorer<FX_FILESIZE> save_pos(&m_Pos); |
| 479 m_Pos = dwSignValuePos; | 479 m_Pos = dwSignValuePos; |
| 480 pDict->SetAt("Contents", GetObject(pObjList, objnum, gennum, false)); | 480 pDict->SetFor("Contents", GetObject(pObjList, objnum, gennum, false)); |
| 481 } | 481 } |
| 482 | 482 |
| 483 FX_FILESIZE SavedPos = m_Pos; | 483 FX_FILESIZE SavedPos = m_Pos; |
| 484 CFX_ByteString nextword = GetNextWord(nullptr); | 484 CFX_ByteString nextword = GetNextWord(nullptr); |
| 485 if (nextword != "stream") { | 485 if (nextword != "stream") { |
| 486 m_Pos = SavedPos; | 486 m_Pos = SavedPos; |
| 487 return pDict.release(); | 487 return pDict.release(); |
| 488 } | 488 } |
| 489 return ReadStream(pDict.release(), objnum, gennum); | 489 return ReadStream(pDict.release(), objnum, gennum); |
| 490 } | 490 } |
| 491 | 491 |
| 492 if (word == ">>") | 492 if (word == ">>") |
| 493 m_Pos = SavedObjPos; | 493 m_Pos = SavedObjPos; |
| 494 | 494 |
| 495 return nullptr; | 495 return nullptr; |
| 496 } | 496 } |
| 497 | 497 |
| 498 CPDF_Object* CPDF_SyntaxParser::GetObjectByStrict( | 498 CPDF_Object* CPDF_SyntaxParser::GetObjectForStrict( |
| 499 CPDF_IndirectObjectHolder* pObjList, | 499 CPDF_IndirectObjectHolder* pObjList, |
| 500 uint32_t objnum, | 500 uint32_t objnum, |
| 501 uint32_t gennum) { | 501 uint32_t gennum) { |
| 502 CFX_AutoRestorer<int> restorer(&s_CurrentRecursionDepth); | 502 CFX_AutoRestorer<int> restorer(&s_CurrentRecursionDepth); |
| 503 if (++s_CurrentRecursionDepth > kParserMaxRecursionDepth) | 503 if (++s_CurrentRecursionDepth > kParserMaxRecursionDepth) |
| 504 return nullptr; | 504 return nullptr; |
| 505 | 505 |
| 506 FX_FILESIZE SavedObjPos = m_Pos; | 506 FX_FILESIZE SavedObjPos = m_Pos; |
| 507 bool bIsNumber; | 507 bool bIsNumber; |
| 508 CFX_ByteString word = GetNextWord(&bIsNumber); | 508 CFX_ByteString word = GetNextWord(&bIsNumber); |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 580 GetObject(pObjList, objnum, gennum, true)); | 580 GetObject(pObjList, objnum, gennum, true)); |
| 581 if (!obj) { | 581 if (!obj) { |
| 582 uint8_t ch; | 582 uint8_t ch; |
| 583 while (GetNextChar(ch) && ch != 0x0A && ch != 0x0D) { | 583 while (GetNextChar(ch) && ch != 0x0A && ch != 0x0D) { |
| 584 continue; | 584 continue; |
| 585 } | 585 } |
| 586 return nullptr; | 586 return nullptr; |
| 587 } | 587 } |
| 588 | 588 |
| 589 if (key.GetLength() > 1) { | 589 if (key.GetLength() > 1) { |
| 590 pDict->SetAt(CFX_ByteString(key.c_str() + 1, key.GetLength() - 1), | 590 pDict->SetFor(CFX_ByteString(key.c_str() + 1, key.GetLength() - 1), |
| 591 obj.release()); | 591 obj.release()); |
| 592 } | 592 } |
| 593 } | 593 } |
| 594 | 594 |
| 595 FX_FILESIZE SavedPos = m_Pos; | 595 FX_FILESIZE SavedPos = m_Pos; |
| 596 CFX_ByteString nextword = GetNextWord(nullptr); | 596 CFX_ByteString nextword = GetNextWord(nullptr); |
| 597 if (nextword != "stream") { | 597 if (nextword != "stream") { |
| 598 m_Pos = SavedPos; | 598 m_Pos = SavedPos; |
| 599 return pDict.release(); | 599 return pDict.release(); |
| 600 } | 600 } |
| 601 | 601 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 620 | 620 |
| 621 if (byte1 == '\r' || byte1 == '\n') | 621 if (byte1 == '\r' || byte1 == '\n') |
| 622 return 1; | 622 return 1; |
| 623 | 623 |
| 624 return 0; | 624 return 0; |
| 625 } | 625 } |
| 626 | 626 |
| 627 CPDF_Stream* CPDF_SyntaxParser::ReadStream(CPDF_Dictionary* pDict, | 627 CPDF_Stream* CPDF_SyntaxParser::ReadStream(CPDF_Dictionary* pDict, |
| 628 uint32_t objnum, | 628 uint32_t objnum, |
| 629 uint32_t gennum) { | 629 uint32_t gennum) { |
| 630 CPDF_Object* pLenObj = pDict->GetObjectBy("Length"); | 630 CPDF_Object* pLenObj = pDict->GetObjectFor("Length"); |
| 631 FX_FILESIZE len = -1; | 631 FX_FILESIZE len = -1; |
| 632 CPDF_Reference* pLenObjRef = ToReference(pLenObj); | 632 CPDF_Reference* pLenObjRef = ToReference(pLenObj); |
| 633 | 633 |
| 634 bool differingObjNum = !pLenObjRef || (pLenObjRef->GetObjList() && | 634 bool differingObjNum = !pLenObjRef || (pLenObjRef->GetObjList() && |
| 635 pLenObjRef->GetRefObjNum() != objnum); | 635 pLenObjRef->GetRefObjNum() != objnum); |
| 636 if (pLenObj && differingObjNum) | 636 if (pLenObj && differingObjNum) |
| 637 len = pLenObj->GetInteger(); | 637 len = pLenObj->GetInteger(); |
| 638 | 638 |
| 639 // Locate the start of stream. | 639 // Locate the start of stream. |
| 640 ToNextLine(); | 640 ToNextLine(); |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 726 numMarkers = ReadEOLMarkers(streamStartPos + endStreamOffset - 1); | 726 numMarkers = ReadEOLMarkers(streamStartPos + endStreamOffset - 1); |
| 727 if (numMarkers == 1) { | 727 if (numMarkers == 1) { |
| 728 len -= 1; | 728 len -= 1; |
| 729 } | 729 } |
| 730 } | 730 } |
| 731 | 731 |
| 732 if (len < 0) { | 732 if (len < 0) { |
| 733 pDict->Release(); | 733 pDict->Release(); |
| 734 return nullptr; | 734 return nullptr; |
| 735 } | 735 } |
| 736 pDict->SetAtInteger("Length", len); | 736 pDict->SetIntegerFor("Length", len); |
| 737 } | 737 } |
| 738 m_Pos = streamStartPos; | 738 m_Pos = streamStartPos; |
| 739 } | 739 } |
| 740 | 740 |
| 741 if (len < 0) { | 741 if (len < 0) { |
| 742 pDict->Release(); | 742 pDict->Release(); |
| 743 return nullptr; | 743 return nullptr; |
| 744 } | 744 } |
| 745 | 745 |
| 746 uint8_t* pData = nullptr; | 746 uint8_t* pData = nullptr; |
| (...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 980 if (limit && m_Pos == limit) | 980 if (limit && m_Pos == limit) |
| 981 return -1; | 981 return -1; |
| 982 } | 982 } |
| 983 return -1; | 983 return -1; |
| 984 } | 984 } |
| 985 | 985 |
| 986 void CPDF_SyntaxParser::SetEncrypt( | 986 void CPDF_SyntaxParser::SetEncrypt( |
| 987 std::unique_ptr<CPDF_CryptoHandler> pCryptoHandler) { | 987 std::unique_ptr<CPDF_CryptoHandler> pCryptoHandler) { |
| 988 m_pCryptoHandler = std::move(pCryptoHandler); | 988 m_pCryptoHandler = std::move(pCryptoHandler); |
| 989 } | 989 } |
| OLD | NEW |