Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(131)

Side by Side Diff: core/fpdfapi/parser/cpdf_syntax_parser.cpp

Issue 2510223002: Make CPDF_Dictionary use unique pointers. (Closed)
Patch Set: Plug leaks Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 440 matching lines...) Expand 10 before | Expand all | Expand 10 after
451 451
452 if (key == "/Contents") 452 if (key == "/Contents")
453 dwSignValuePos = m_Pos; 453 dwSignValuePos = m_Pos;
454 454
455 std::unique_ptr<CPDF_Object> pObj = 455 std::unique_ptr<CPDF_Object> pObj =
456 GetObject(pObjList, objnum, gennum, true); 456 GetObject(pObjList, objnum, gennum, true);
457 if (!pObj) 457 if (!pObj)
458 continue; 458 continue;
459 459
460 CFX_ByteString keyNoSlash(key.raw_str() + 1, key.GetLength() - 1); 460 CFX_ByteString keyNoSlash(key.raw_str() + 1, key.GetLength() - 1);
461 pDict->SetFor(keyNoSlash, pObj.release()); 461 pDict->SetFor(keyNoSlash, std::move(pObj));
462 } 462 }
463 463
464 // Only when this is a signature dictionary and has contents, we reset the 464 // Only when this is a signature dictionary and has contents, we reset the
465 // contents to the un-decrypted form. 465 // contents to the un-decrypted form.
466 if (pDict->IsSignatureDict() && dwSignValuePos) { 466 if (pDict->IsSignatureDict() && dwSignValuePos) {
467 CFX_AutoRestorer<FX_FILESIZE> save_pos(&m_Pos); 467 CFX_AutoRestorer<FX_FILESIZE> save_pos(&m_Pos);
468 m_Pos = dwSignValuePos; 468 m_Pos = dwSignValuePos;
469 pDict->SetFor("Contents", 469 pDict->SetFor("Contents", GetObject(pObjList, objnum, gennum, false));
470 GetObject(pObjList, objnum, gennum, false).release());
471 } 470 }
472 471
473 FX_FILESIZE SavedPos = m_Pos; 472 FX_FILESIZE SavedPos = m_Pos;
474 CFX_ByteString nextword = GetNextWord(nullptr); 473 CFX_ByteString nextword = GetNextWord(nullptr);
475 if (nextword != "stream") { 474 if (nextword != "stream") {
476 m_Pos = SavedPos; 475 m_Pos = SavedPos;
477 return std::move(pDict); 476 return std::move(pDict);
478 } 477 }
479 return ReadStream(pDict.release(), objnum, gennum); 478 return ReadStream(pDict.release(), objnum, gennum);
480 } 479 }
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
569 if (!obj) { 568 if (!obj) {
570 uint8_t ch; 569 uint8_t ch;
571 while (GetNextChar(ch) && ch != 0x0A && ch != 0x0D) { 570 while (GetNextChar(ch) && ch != 0x0A && ch != 0x0D) {
572 continue; 571 continue;
573 } 572 }
574 return nullptr; 573 return nullptr;
575 } 574 }
576 575
577 if (key.GetLength() > 1) { 576 if (key.GetLength() > 1) {
578 pDict->SetFor(CFX_ByteString(key.c_str() + 1, key.GetLength() - 1), 577 pDict->SetFor(CFX_ByteString(key.c_str() + 1, key.GetLength() - 1),
579 obj.release()); 578 std::move(obj));
580 } 579 }
581 } 580 }
582 581
583 FX_FILESIZE SavedPos = m_Pos; 582 FX_FILESIZE SavedPos = m_Pos;
584 CFX_ByteString nextword = GetNextWord(nullptr); 583 CFX_ByteString nextword = GetNextWord(nullptr);
585 if (nextword != "stream") { 584 if (nextword != "stream") {
586 m_Pos = SavedPos; 585 m_Pos = SavedPos;
587 return std::move(pDict); 586 return std::move(pDict);
588 } 587 }
589 588
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
715 numMarkers = ReadEOLMarkers(streamStartPos + endStreamOffset - 1); 714 numMarkers = ReadEOLMarkers(streamStartPos + endStreamOffset - 1);
716 if (numMarkers == 1) { 715 if (numMarkers == 1) {
717 len -= 1; 716 len -= 1;
718 } 717 }
719 } 718 }
720 719
721 if (len < 0) { 720 if (len < 0) {
722 delete pDict; 721 delete pDict;
723 return nullptr; 722 return nullptr;
724 } 723 }
725 pDict->SetIntegerFor("Length", len); 724 pDict->SetNewFor<CPDF_Number>("Length", static_cast<int>(len));
726 } 725 }
727 m_Pos = streamStartPos; 726 m_Pos = streamStartPos;
728 } 727 }
729 728
730 if (len < 0) { 729 if (len < 0) {
731 delete pDict; 730 delete pDict;
732 return nullptr; 731 return nullptr;
733 } 732 }
734 733
735 uint8_t* pData = nullptr; 734 uint8_t* pData = nullptr;
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
911 if (limit && m_Pos == limit) 910 if (limit && m_Pos == limit)
912 return -1; 911 return -1;
913 } 912 }
914 return -1; 913 return -1;
915 } 914 }
916 915
917 void CPDF_SyntaxParser::SetEncrypt( 916 void CPDF_SyntaxParser::SetEncrypt(
918 std::unique_ptr<CPDF_CryptoHandler> pCryptoHandler) { 917 std::unique_ptr<CPDF_CryptoHandler> pCryptoHandler) {
919 m_pCryptoHandler = std::move(pCryptoHandler); 918 m_pCryptoHandler = std::move(pCryptoHandler);
920 } 919 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698