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

Side by Side Diff: core/src/fpdfapi/fpdf_parser/fpdf_parser_objects.cpp

Issue 1582963003: Fix some iterator invalidation issues while traversing CPDF_Dictionary. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: fix a bug in CPDF_Dictionary::ReplaceKey while we're at it Created 4 years, 11 months 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 2014 PDFium Authors. All rights reserved. 1 // Copyright 2014 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/include/fpdfapi/fpdf_objects.h" 7 #include "core/include/fpdfapi/fpdf_objects.h"
8 8
9 #include <algorithm> 9 #include <algorithm>
10 10
(...skipping 716 matching lines...) Expand 10 before | Expand all | Expand 10 after
727 void CPDF_Dictionary::ReplaceKey(const CFX_ByteStringC& oldkey, 727 void CPDF_Dictionary::ReplaceKey(const CFX_ByteStringC& oldkey,
728 const CFX_ByteStringC& newkey) { 728 const CFX_ByteStringC& newkey) {
729 ASSERT(m_Type == PDFOBJ_DICTIONARY); 729 ASSERT(m_Type == PDFOBJ_DICTIONARY);
730 auto old_it = m_Map.find(oldkey); 730 auto old_it = m_Map.find(oldkey);
731 if (old_it == m_Map.end()) 731 if (old_it == m_Map.end())
732 return; 732 return;
733 733
734 // Avoid 2 constructions of CFX_ByteString. 734 // Avoid 2 constructions of CFX_ByteString.
735 CFX_ByteString newkey_bytestring = newkey; 735 CFX_ByteString newkey_bytestring = newkey;
736 auto new_it = m_Map.find(newkey_bytestring); 736 auto new_it = m_Map.find(newkey_bytestring);
737 if (new_it == old_it)
Lei Zhang 2016/01/14 01:32:29 Can't we move this to the top and check if |oldkey
Oliver Chang 2016/01/14 01:44:21 Hmm, I did that at first, but thought that this wa
738 return;
739
737 if (new_it != m_Map.end()) { 740 if (new_it != m_Map.end()) {
738 new_it->second->Release(); 741 new_it->second->Release();
739 new_it->second = old_it->second; 742 new_it->second = old_it->second;
740 } else { 743 } else {
741 m_Map.insert(std::make_pair(newkey_bytestring, old_it->second)); 744 m_Map.insert(std::make_pair(newkey_bytestring, old_it->second));
742 } 745 }
743 m_Map.erase(old_it); 746 m_Map.erase(old_it);
744 } 747 }
745 FX_BOOL CPDF_Dictionary::Identical(CPDF_Dictionary* pOther) const { 748 FX_BOOL CPDF_Dictionary::Identical(CPDF_Dictionary* pOther) const {
746 if (!pOther) { 749 if (!pOther) {
(...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after
1130 pObj->Destroy(); 1133 pObj->Destroy();
1131 return FALSE; 1134 return FALSE;
1132 } 1135 }
1133 it->second->Destroy(); 1136 it->second->Destroy();
1134 } 1137 }
1135 pObj->m_ObjNum = objnum; 1138 pObj->m_ObjNum = objnum;
1136 m_IndirectObjs[objnum] = pObj; 1139 m_IndirectObjs[objnum] = pObj;
1137 m_LastObjNum = std::max(m_LastObjNum, objnum); 1140 m_LastObjNum = std::max(m_LastObjNum, objnum);
1138 return TRUE; 1141 return TRUE;
1139 } 1142 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698