summaryrefslogtreecommitdiff
path: root/fpdfsdk/fpdf_ppo.cpp
diff options
context:
space:
mode:
authorTom Sepez <tsepez@chromium.org>2018-10-17 17:57:51 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-10-17 17:57:51 +0000
commit5ae6c564d16ce8b625df3d1950abc822f9ecc987 (patch)
tree96bb64df3166e46db397e405789588bf8dc53842 /fpdfsdk/fpdf_ppo.cpp
parent785a26dc649af80c593f899a606dff4dae7c48fd (diff)
downloadpdfium-5ae6c564d16ce8b625df3d1950abc822f9ecc987.tar.xz
Add CPDF_{Array,Dictionary}Locker to catch illegal iteration patterns.
Move begin/end methods onto locker object which tracks whether iterators are in existence. Change-Id: Ia869f313fce48d10a0d0180d0cc083eed6ea1584 Reviewed-on: https://pdfium-review.googlesource.com/c/44070 Reviewed-by: Lei Zhang <thestig@chromium.org> Commit-Queue: Tom Sepez <tsepez@chromium.org>
Diffstat (limited to 'fpdfsdk/fpdf_ppo.cpp')
-rw-r--r--fpdfsdk/fpdf_ppo.cpp29
1 files changed, 17 insertions, 12 deletions
diff --git a/fpdfsdk/fpdf_ppo.cpp b/fpdfsdk/fpdf_ppo.cpp
index fd270d997c..5c5930e097 100644
--- a/fpdfsdk/fpdf_ppo.cpp
+++ b/fpdfsdk/fpdf_ppo.cpp
@@ -360,18 +360,22 @@ bool CPDF_PageOrganizer::UpdateReference(CPDF_Object* pObj,
}
case CPDF_Object::DICTIONARY: {
CPDF_Dictionary* pDict = pObj->AsDictionary();
- auto it = pDict->begin();
- while (it != pDict->end()) {
- const ByteString& key = it->first;
- CPDF_Object* pNextObj = it->second.get();
- ++it;
- if (key == "Parent" || key == "Prev" || key == "First")
- continue;
- if (!pNextObj)
- return false;
- if (!UpdateReference(pNextObj, pObjNumberMap))
- pDict->RemoveFor(key);
+ std::vector<ByteString> bad_keys;
+ {
+ CPDF_DictionaryLocker locker(pDict);
+ for (auto it = locker.begin(); it != locker.end(); ++it) {
+ const ByteString& key = it->first;
+ if (key == "Parent" || key == "Prev" || key == "First")
+ continue;
+ CPDF_Object* pNextObj = it->second.get();
+ if (!pNextObj)
+ return false;
+ if (!UpdateReference(pNextObj, pObjNumberMap))
+ bad_keys.push_back(key);
+ }
}
+ for (const auto& key : bad_keys)
+ pDict->RemoveFor(key);
break;
}
case CPDF_Object::ARRAY: {
@@ -471,7 +475,8 @@ bool CPDF_PageExporter::ExportPage(const std::vector<uint32_t>& pageNums,
return false;
// Clone the page dictionary
- for (const auto& it : *pSrcPageDict) {
+ CPDF_DictionaryLocker locker(pSrcPageDict);
+ for (const auto& it : locker) {
const ByteString& cbSrcKeyStr = it.first;
if (cbSrcKeyStr == pdfium::page_object::kType ||
cbSrcKeyStr == pdfium::page_object::kParent) {